Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  ProGuard tuning  (Read 4137 times)
0 Members and 1 Guest are viewing this topic.
Offline M2009

Junior Member





« Posted 2009-06-04 18:45:40 »

Hi, I have a question about increasing performance with ProGuard.

If I have this code...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
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.)

1  
2  
3  
4  
5  
6  
7  
8  
9  
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.

Offline jezek2
« Reply #1 - Posted 2009-06-05 07:28:49 »

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.

You don't need that, JVM already does that. It simply inlines very small methods (eg. getters/setters) so the native code ends up with accessing the variable directly. I wouldn't use any bytecode optimizers as JVM best understands code produced by javac. Sure, it can run any valid bytecode, but it might be slower because it doesn't match some bytecode optimization patterns in JVM.

The only reasonable way to optimize is to run the whole actual application/game in profiler and check where hotspots are and try to optimize these afterwards. You would be surprised that actual hotspots can be pretty much different than what you've thought.
Offline M2009

Junior Member





« Reply #2 - Posted 2009-06-05 22:02:43 »

Ah, thanks. I'm glad to hear it, now I don't have to feel ineffective when I use getters/setters. Smiley

What is/how do I run the application through a profiler? I have never done that before.

Btw, maybe you can help me with another ProGuard question I have up on a different secrion of the forum?
Here's the link: http://www.java-gaming.org/topics/why-doesn-t-the-proguard-output-work/20582/view.html

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Abuse

JGO Coder


Medals: 11


falling into the abyss of reality


« Reply #3 - Posted 2009-06-06 02:55:29 »

Going back to your original example, I believe proguard would be able to make much more aggressive optimisations in the example case you give.

It would detect that the 'number' member is private, and written to only once (in the class constructor), and therefore be able to treat it as a constant - eliminating the member entirely.
The call to getNumber() would be inlinable, which in turn would make the construction of the Counter instance a no-op.
As a result the entire Counter class would become redundant.

So I would hope the code you would end up with would simply be :-

1  
2  
3  
4  
5  
public class Application {
public static void main(String [] args) {
System.out.println(1);
}
}


Ofcourse, the easiest way of checking this is to simply run your code sample through proguard, and then decompile/disassemble it with dj/javap.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline M2009

Junior Member





« Reply #4 - Posted 2009-06-06 14:38:04 »

Interesting thought, that's probably true. Smiley I hope.

Still looking for answer to:

Quote
What is/how do I run the application through a profiler? I have never done that before.

Offline jezek2
« Reply #5 - Posted 2009-06-06 14:48:17 »

You can try NetBeans profiler, I think it's also included in VisualVM which is part of newer JDKs.
Offline Mike

JGO Ninja


Medals: 71
Projects: 1
Exp: 5 years


Java guru wanabee


« Reply #6 - Posted 2009-06-06 22:59:46 »

It's also really easy to download and integrate JProfiler. There is a free trial of 10 days on their website and it took me 10 min to get a button in Eclipse next to the run button that profiles the applet.

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline M2009

Junior Member





« Reply #7 - Posted 2009-06-07 13:25:20 »

If it costs money it's not for me, and I'd prefer not having to get NetBeans. Found a folder named "profiler2" in Java\jdk1.6.0_11\lib\visualvm but I don't know how that works.

Is there a way of getting a profiler-button in Eclipse for free? Any alternatives (non-trial)?

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #8 - Posted 2009-06-07 18:29:02 »

Although I'm not a fan of Netbeans, the profiler is pretty good. You don't need to setup your project in NB either - just run your game from Eclipse as normal and then NB's dynamic attach method will just give you a list of running Java apps to attach to and profile. Just think of NB as a stand-alone profiler. Wink

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline M2009

Junior Member





« Reply #9 - Posted 2009-06-14 16:04:33 »

Okay, thanks. I'll remember that, sounds smart.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #10 - Posted 2009-06-18 14:01:22 »

I once gave ProGuard a shot by letting it optimize JEmu (which is a seriously CPU performance critical thing). It actually made it slower.

I guess ProGuard can make sense for really simple JVMs (interpreters, J2ME) but a proper JVM like HotSpots seems to perform it's optimization jobs quite well on its own. Perhaps ProGuard often changes the code in such a way that HotSpot can not make any assumptions anymore to apply its smarter optimization methods.

Offline ido

Junior Member





« Reply #11 - Posted 2009-06-29 14:56:22 »

ProGuard optimizes mostly for file size as far as I know (and it can get .class/.jars quite a bit smaller).

-Ido.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (34 views)
2014-07-18 06:55:21

Zero Volt (30 views)
2014-07-17 23:47:54

danieldean (25 views)
2014-07-17 23:41:23

MustardPeter (27 views)
2014-07-16 23:30:00

Cero (42 views)
2014-07-16 00:42:17

Riven (44 views)
2014-07-14 18:02:53

OpenGLShaders (32 views)
2014-07-14 16:23:47

Riven (34 views)
2014-07-14 11:51:35

quew8 (30 views)
2014-07-13 13:57:52

SHC (66 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!