How to do object pooling right?

Sure you can!

Here are several options I use when debugging:
-server
-XX:+PrintGCDetails
-XX:-PrintGCTimeStamps
-XX:+TraceClassUnloading
-XX:+PrintCompilation <-- shows when java byte code has been transformed to machine code

Thanks a lot for the info on escape analysis and scalar replacement. In combination they will exactly get rid of those unwanted new()s of local helper vector variables.

I believe that I ran my tests with the client vm (=default in my IDE), but I’ll do more tests soon.

Thanks again, I didn’t know that the hotspot compiler is able to do that!

@ClickerMonkey: The debug build you have to compile yourself and has MORE options. For this discussion the release build doesn’t have the option that spews out what "new"s are found to not escape their calling stack frame, not the one that tells you which have had scalar replacement applied. Of course you could poor over the assem output…but that’s much more work. (Oh and that requires linux or compile the plug-in yourself.)

Also, who cares about the output! The idea of all the fancy things the JVM does is so you can write code that looks sane, and it takes care of trying to make it fast. If it’s not fast, it’s likely a different approach is needed, rather than poring over machine code output; particularly as the behaviour will simply change from one JVM to the next.

Cas :slight_smile:

I general I agree, my point being before spending time making stuff faster, first insure that what you’re attempt to address is part of the performance problem…and if indeed it is, then check that the plan you have in mind has a reasonable expectation of being a win and evaluate if the expected engineering cost is deemed to be worthwhile. When you’re thinking about arm wrestling you’re compiler you need to know what you’re up against and where to focus your efforts.

Server VM (and therefore EscapeAnalysis) is not present in client VM - which is the only one in 32-bit JRE on Windows.

This also does not apply to Dalvik. They did testing on escape analysis but I don’t know why didn’t they include it. It gives soo much performance gain, ugh.

Thankfully, on Linux machines (and probably Mac too) server VM is present (with -server switch) and on 64-bit JRE on Windows server VM is also default. (Sadly almost no-one has 64 bit JVM on Windows)

Good thing is (if you are not targeting Android or iOS) you can ship JRE with server VM on Windows with your app legally. Bad thing is it weights much… You can remove some things from it, but rt.jar still weights a f**kton…
http://www.oracle.com/technetwork/java/javase/jre-7-readme-430162.html

Again, good thing is, There are unofficial OpenJDK builds for Windows - and you can strip them off of everything that is unnecessary. Including contents of rt.jar - but you should be careful not to remove something important.

edit: see posts below

Server VM (and therefore EscapeAnalysis) is not present in client VM - which is the only one in 32-bit JRE on Windows.

This also does not apply to Dalvik. They did testing on escape analysis but I don’t know why didn’t they include it. It gives soo much performance gain, ugh.

Thankfully, on Linux machines (and probably Mac too) server VM is present (with -server switch) and on 64-bit JRE on Windows server VM is also default. (Sadly almost no-one has 64 bit JVM on Windows)

Good thing is (if you are not targeting Android or iOS) you can ship JRE with server VM on Windows with your app legally. Bad thing is it weights much… You can remove some things from it, but rt.jar still weights a f**kton…
http://www.oracle.com/technetwork/java/javase/jre-7-readme-430162.html

Again, good thing is, There are unofficial OpenJDK builds for Windows - and you can strip them off of everything that is unnecessary. Including contents of rt.jar - but you should be careful not to remove something important.

edit: see posts below

I bundle an OpenJDK JRE with Spine. Weighs ~13MB.
https://code.google.com/p/libgdx/wiki/BundlingJRE

I bundle an OpenJDK JRE with Spine. Weighs ~13MB.
https://code.google.com/p/libgdx/wiki/BundlingJRE

also server vm is just one dll to copy :persecutioncomplex:

also server vm is just one dll to copy :persecutioncomplex:

Behold!

http://downloads.puppygames.net/SetupUltratron.exe
http://downloads.puppygames.net/Ultratron_MacOSX.zip
http://downloads.puppygames.net/Ultratron.tar.gz

That’s your baseline sizes pretty much. I couldn’t get them much smaller without “cheating”.

And if you were wondering without having to delve into the .sh files, the commandline args look like:
-server
-XX:+TieredCompilation
-XX:Tier2CompileThreshold=70000
-XX:+DoEscapeAnalysis
-Xms64m
-Xmx256m
-Xincgc \

Cas :slight_smile:

Behold!

http://downloads.puppygames.net/SetupUltratron.exe
http://downloads.puppygames.net/Ultratron_MacOSX.zip
http://downloads.puppygames.net/Ultratron.tar.gz

That’s your baseline sizes pretty much. I couldn’t get them much smaller without “cheating”.

And if you were wondering without having to delve into the .sh files, the commandline args look like:
-server
-XX:+TieredCompilation
-XX:Tier2CompileThreshold=70000
-XX:+DoEscapeAnalysis
-Xms64m
-Xmx256m
-Xincgc \

Cas :slight_smile:

A few more fine jvm options, that you should at least try


-XX:MaxPermSize=20M // this or 30m, typically my apps never needed more for perm size
-XX:MaxInlineSize=512
-XX:FreqInlineSize=512
-XX:InlineSmallCode=2000
-XX:+UseFastAccessorMethods
-XX:-DontCompileHugeMethods

back to OpenJDK

For Linux: OpenJDK already contains server VM. Should be pre-installed. If not, user can install it with one command line, no need to bundle it.

For MacOSX: Probably contains server VM already, no need to bundle.

For Window: 32 bit constains only client vm, you should bundle openjdk.
If user somehow has 64 bit jvm, then it has server vm only, no need to bundle - but users don’t usually have 64 bit vm…

http://dwn.keraj.net/OpenJRE-7u6-windows-i386.7z - 8mb

  • rt.jar is not compressed - 24mb - so 7zip can compress it more efficiently. (resulting in 8mb package)

A few more fine jvm options, that you should at least try


-XX:MaxPermSize=20M // this or 30m, typically my apps never needed more for perm size
-XX:MaxInlineSize=512
-XX:FreqInlineSize=512
-XX:InlineSmallCode=2000
-XX:+UseFastAccessorMethods
-XX:-DontCompileHugeMethods

back to OpenJDK

For Linux: OpenJDK already contains server VM. Should be pre-installed. If not, user can install it with one command line, no need to bundle it.

For MacOSX: Probably contains server VM already, no need to bundle.

For Window: 32 bit constains only client vm, you should bundle openjdk.
If user somehow has 64 bit jvm, then it has server vm only, no need to bundle - but users don’t usually have 64 bit vm…

http://dwn.keraj.net/OpenJRE-7u6-windows-i386.7z - 8mb

  • rt.jar is not compressed - 24mb - so 7zip can compress it more efficiently. (resulting in 8mb package)

Best compression: jar -> uncompressed pack200 -> lzma

Best compression: jar -> uncompressed pack200 -> lzma