Hi, I have a question about increasing performance with ProGuard.
If I have this code…
public class Counter {
private int number = 1;
public int getNumber() {
return number;
}
}
public class Application {
public static void main(String[] args) {
Counter c = new Counter();
System.out.println(c.getCounter());
}
}
…and then optimize the code with ProGuard, will the code turn out like this then? (I haven’t taken into consideration other optimizations ProGuard might do, such as removing the “c”-variable since it’s only used once.)
public class Counter {
public int number = 1;
}
public class Application {
public static void main(String[] args) {
Counter c = new Counter();
System.out.println(c.number);
}
}
Since the getter is very simple and only gives back the value of number this would be a good way to save some operations. If ProGuard does in fact do this I would feel a lot better since I feel like every time I’m making getters and setters I reduce the speed of my application by half. I know the extra method calls won’t be noticable unless it’s done a billion times every second, but still.
ProGuard does have a “Allow access modification” checkbox on the “Optimization” page (using proguardgui.jar) so I would like to believe it does set private attributes to public and replaces simple getters and setters calls with direct access (since it doesn’t really matter to the byte code if a attribute is securely encapsulated or not).
Anyone knows? I’ve been searching around but I can’t find any mentioning concerning this matter on the net.
Edit: Fixed tabs, added a bit of text.