Garbage Collection and Skipped Turns
← Thread:Talk:XanderCat/Garbage Collection and Skipped Turns/reply (7)
This is correct.
My understanding of the snippet above is that you have 3 variables. 2 local in the stack (references "a" and "b") and 1 in the heap (Object instance).
Some variables stay in the stack only, like primitives (double, float, int...).
Where would a primitive array like an int[] end up?
Java treats an array as an object, so on the heap.
However, these days the JVM is more intelligent than you guys are giving it credit for, eg. it has Escape Analysis to determine if objects should be put on the stack if they stay local.
Didn´t know about escape analysis.
What I usually do to take in account all optimizations, even those I don´t know about, is to use profiling tools. Measure what is really happening, instead of looking at the code and guessing.
You do not have permission to edit this page, for the following reasons:
You can view and copy the source of this page.
Return to Thread:Talk:XanderCat/Garbage Collection and Skipped Turns/reply (16).
When I do profiling in Robocode, I run a battle of a bot against itself. Then I filter the results by package so engine data is filtered out and only data from my bots appear in the profiling report.
What profiling tool do you use? I haven't tried that many, but I've been rather unsuccessful trying to use profiling tools on Robocode. The last one I tried was Visual VM, but when you try to profile a running instance of Robocode with Visual VM, it prompts for a username and password. I kind of gave up and assumed I would run into similar trouble with all profiling tools, either due to the Robocode security setup or due to the odd way that Robocode loads classes and sandboxes robots. If you know of a profiling tool that works with existing Robocode, please share!
I tried VisualVM and when it asked for username/pw I just did a/a and it worked, I suspect it asks for them but doesn't actually use them.
Make sure you start robocode with -Ddebug=true so that it disables skipped turns!
I got Visual VM working and running through Eclipse too. Its a bit unintuitive to set up through Eclipse but its working now and easy to run. As MN says you can filter out any results from specific packages and just profile your bot (though its worth noting that you might want to leave any java data structure packages such as the Vector class if you use it a lot in your robot).
I managed to get my movement running pretty fast within an hour of getting Visual VM running! :D
If I find the time I might write a wiki page on how to get it up and running in Eclipse and how to set it up to profile your robot.
I just use eclipse, but it took so long that I never really did much profiling (with that). Instead, I timed a bunch of candidates for worst cpu usage and printed the times to the console and then focused on those. All of that, until I realized that I was the only bot evaluating 20 points on the secondary waves :-) When I changed that, I think Gilgalad became one of the fastest bots in the top ten.
Some things to optimize: wall smoothing, I think I recall that you used your own algorithm for this. How fast is that? Geometry methods: How efficient are your precise intersection methods?
I assume you already cache your wave data?
what sort of danger function do you use for surfing?
I never really had trouble with gun speed (yet... we'll see what my latest ideas do to that) so I assume you wouldn't either, but you could at least add some code to verify this.
Yes. However anything that you are creating during a function and keeping hold of for a few frames and then releasing is going to be allocating on the stack. Stuff like "Wave" objects, "Bullet" objects or whatever else you use in your bot will cause GC stalls if you create lots, use for a while and then null. This is where the pooling comes into force. I would definitely recommend pooling objects such as waves etc if you are having trouble with stalls and then go from there.
-wolfman
See, my bot always had a skipped turns problem, and now you're giving me a possible solution. You're drawing me right back in to wanting to start Robocoding again, dangit! *laughing*
Arrays are objects in java:
public void func() {
int[] myArray; // myArray variable on the stack myArray = new int[5]; // Array object allocated on heap, referenced by myArray variable on the stack
}
Note that member variables of objects are obviously going to take up memory on the heap not the stack - eg if you have 30 primitive member variables (ints, doubles etc) of a class and call new on that class, it will take up more memory allocation than a class that has 1 primitive member variable.
However allocating 30 local primitive variables during a function call allocates those primitive types on the stack alongside you local member reference variables.