shawnkendall
|
 |
«
Posted
2003-10-27 16:41:43 » |
|
Hi all, Well I am quite happy to report that after exhaustive testing, my team is adopted ArrayLists from the java.util/Collections APIs for container functionality in final core game engine classes.
Previous testing on several Collection classes has shown less than please results WRT performance, class size and extraneous garbage collection.
It seems 1.4.2 gc is really handling Collection issues well, so well in fact that we are slowly adopting in more as we see fit. With this adoption, Java 1.5 will also be able to take advantage of the new "for" syntax and run-time benefits.
For us, this is a significant change, as in the past we have publicly "denounced" the Collections APIs in PRODUCTION level game code. For tools and prototyping fine, but high performance, very controlled per frame code, no. With the latest VM (on Windows at least), we can found ArrayLists to be of production level quality when needing a growable/dynamic sized list.
Last years GDC presentation on this topic yielded some interesting (heated) floor discussion about Collections and GCing. In the end, we still did not endorse them. However, this year we will endorse a growing sub-set as testing progresses.
For many of you, this probably means squat as you either didn't care, or were already convinced on using Collections. :-) For those who weren't (read C game developers reviewing Java) our position is that it is now an option.
|
|
|
|
Herkules
|
 |
«
Reply #1 - Posted
2003-10-27 16:54:39 » |
|
Very good to hear  So I don't have to change my code. Hm, not too many collections besides HashMap in there anyway .... most for listeners and such.
|
|
|
|
William
|
 |
«
Reply #2 - Posted
2003-10-27 17:19:26 » |
|
Nice to hear  Now I'm just curious about how the GC and optimizer will perform for primitive collections that use the auto-boxing feature in Java 1.5. Can, and will, the optimizer make these an alternative to custom-written primitive collections for performance-critical code, or will the boxing/unboxing slow things down too much? Anyone know how well the C# VM optimizes these?
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
shawnkendall
|
 |
«
Reply #3 - Posted
2003-10-28 00:53:28 » |
|
YEAH... that is a good question. I have seen several very nice "int" HashMaps (not Integer) Auto-boxing will make it SEEM like "int" but will it run like "int" ?:-)
|
|
|
|
princec
|
 |
«
Reply #4 - Posted
2003-10-28 08:38:37 » |
|
Well, obviously not - it's got to construct an object on the heap somewhere, where it might linger awhile and end up fragmenting memory a bit, and later on it'll have to garbage collect it at some point. None of which is entirely cost-free, as an int is. It'll all come down to the nitty-gritty fine detail, as usual... Cas 
|
|
|
|
Java Cool Dude
|
 |
«
Reply #5 - Posted
2003-10-28 08:50:04 » |
|
Umm I happen to use Vectors in my 3D application, question now: Are arrayLists faster than Vectors?
|
|
|
|
|
aldacron
Senior Member    Medals: 4
Java games rock!
|
 |
«
Reply #6 - Posted
2003-10-28 09:04:04 » |
|
The methods of a Vector are threadsafe (synchronized), where ArrayLists are not. So if you aren't sharing the collection across threads, ArrayLists are recommended.
|
|
|
|
|
Jeff
|
 |
«
Reply #7 - Posted
2003-10-28 18:56:12 » |
|
I would add further that Vectors are a dead develoment line (same as Hashtable) so UNLESS you need 1.1 compatability use the collection classes instead.
|
|
|
|
Athomas Goldberg
|
 |
«
Reply #8 - Posted
2003-10-29 03:11:08 » |
|
I would add further that Vectors are a dead develoment line (same as Hashtable) so UNLESS you need 1.1 compatability use the collection classes instead. For the same reasons, if you *do* need a synchronized list it's recommended that you use Collections.synchronizedList() rather than Vector.
|
Athomas Goldberg Project Lead / Wildcard Game Technologies Group Sun Microsystems, Inc.
|
|
|
MickeyB
|
 |
«
Reply #9 - Posted
2003-11-25 16:48:38 » |
|
Let me get this straight. If I plan to convert my game to multiplayer and have numerous client threads access a "list" of sectors/rooms/whateva, I should use Collections.synchronizedList() to store my list of objects that I will loop through for sending data to clients?
M
|
|
|
|
Games published by our own members! Check 'em out!
|
|
tom
|
 |
«
Reply #10 - Posted
2003-11-25 18:03:10 » |
|
Yes. Collections.synchronizedList() will prevent the list from being corrupted when more than one thread is using it. But you would also need additional synchronization to prevent the list from changing while you are iterating it.
|
|
|
|
MickeyB
|
 |
«
Reply #11 - Posted
2003-11-25 18:21:25 » |
|
thanks tom! Great pic by the way...would have hated to run into it in the pen and paper days.  M
|
|
|
|
Seekely
Senior Newbie 
I am java
|
 |
«
Reply #12 - Posted
2003-11-26 13:08:46 » |
|
Nice to hear  Now I'm just curious about how the GC and optimizer will perform for primitive collections that use the auto-boxing feature in Java 1.5. Can, and will, the optimizer make these an alternative to custom-written primitive collections for performance-critical code, or will the boxing/unboxing slow things down too much? Anyone know how well the C# VM optimizes these? Isn't this and the casting feature they are adding simply going to be dirty compiler tricks instead of at runtime?
|
|
|
|
William
|
 |
«
Reply #13 - Posted
2003-11-26 21:22:08 » |
|
Isn't this and the casting feature they are adding simply going to be dirty compiler tricks instead of at runtime? The techniques will be performed at compile time, yes. That's perfectly appropriate for eliminating casts since the only benefits you get from generics are clearer code and compile-time type safety. At least Sun's VM has optimized away the cost of casts in all the apps I have benchmarked, so performance isn't an issue there. I also don't know of any runtime optimization specificly for autoboxing objects (which is why I asked about it). The object creation optimizations (like generational garbage collection) that Hotspot uses seem to apply to all object allocations, so I can't see any good reason to break backwards compatability and make autoboxing a part of the VM.
|
|
|
|
|
swpalmer
|
 |
«
Reply #14 - Posted
2003-11-27 04:45:39 » |
|
Yes. Collections.synchronizedList() will prevent the list from being corrupted when more than one thread is using it. But you would also need additional synchronization to prevent the list from changing while you are iterating it. I find a lot of the time I can just get rid of the synchronized collection because of this extra synchronization that must be added anyway for keeping the list constant while iterating over it. I the add/remove methods I call have to use this 'additional' synchronization anyway, so what good is the synchronization that is built-in? It's redundant.
|
|
|
|
|