• Post Reply Bookmark Topic Watch Topic
  • New Topic

"unrolling" lists

 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my game, I have a couple hundred objects called Fella, with a left leg, a right leg, a torso, a head, and two arms. I frequently have a command I want to run on all of them. Currently, I have them all in an ArrayList, and just iterate through the list. Would there be notable performance gains if I unrolled this list, and called the method on each one individually?

Thanks,
Nick
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Offhand I doubt it. Maybe if you're issuing lots and lots of very short commands. I which case I might consider creating composite commands, combining multiple short commands into a few long commands. But experimentations beats speculation here. Do you currently have a performance problem? Have you taken a look at the executing code in a profiler?
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't figure it would.
I've never gotten around to figuring out how to work a profile. I will at some point. I've done a bunch of other performance boosters, and they've helped. Offhand, do you by any chance know if OpenGL (JoGL) calculates everything out for displays that aren't in the view screen? That is to say, would it be benificial to make sure something will be visible before I display it?

Thanks,
Nick
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No idea here. That seems like an important-enough thing to do that it does seem very plausible OpenGL might do it for you, but I don't know.
 
Virag Saksena
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It it highly unlikely you are going to get any gains.
Since your loop iteration primitives are allocated on a stack, it is quite fast. You can check the overhead for yourself with a null iteration.

If you array is fellas, put in ...
long endTime = 0, startTime = System.currentTimeMillis();
for (int i = 0; i < fellas.length; i++)
;;
long startTime = System.currentTimeMillis();
System.err.println("Loop iteration (ms) : "+endTime-startTime);

I doubt you'd see even a millisecond.
Of course you could even go ...
for (int i = fellas.length - 1; i > -1; i--)
to reduce the overhead if you still wanted to

Compare it with the actual operation you are doing, to see if it even worth optimizing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!