Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411507 Posts in 69374 Topics- by 58429 Members - Latest Member: Alternalo

April 26, 2024, 05:46:43 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)TutorialsTaming Java GC to prevent stutter, an in-depth post on memory management
Pages: [1]
Print
Author Topic: Taming Java GC to prevent stutter, an in-depth post on memory management  (Read 3655 times)
Zarkonnen
Level 1
*


Games! Kittens! Wine!


View Profile WWW
« on: April 23, 2014, 02:23:38 AM »

Spurred on by this post, here is an in-depth post on memory management in Airships.

Excerpt:

The game is written in Java, where unused data is automatically deleted in a process called garbage collection. This is nice, but comes with a big drawback: you can't control when garbage collection (GC) happens, and it can take too long.

The game runs at 60 frames per second, giving each frame a bit more than 16 milliseconds to advance the game state and redraw the screen. If GC kicks in during a frame and takes 30 milliseconds, the game stutters noticeably.

So this is something that needs fixing.

Read the rest
Logged

Chromanoid
Level 10
*****



View Profile
« Reply #1 on: April 23, 2014, 12:13:25 PM »

Nice article, yet I doubt object creation is that problematic with a modern JVM. Especially short lived objects usually should not affect performance, see http://programmers.stackexchange.com/questions/149563/should-we-avoid-object-creation-in-java

Relevant thread: http://forums.tigsource.com/index.php?topic=22054.0
« Last Edit: April 23, 2014, 12:21:52 PM by Chromanoid » Logged
MontyOnTheRun
Level 0
*


View Profile
« Reply #2 on: April 23, 2014, 06:25:33 PM »

Amazing references. My universe has just expanded! 
Hours and hours to read.
Beer!
Logged
Julien
Level 2
**


View Profile
« Reply #3 on: April 23, 2014, 10:53:36 PM »

Thanks a lot !! Smiley
Logged

Zarkonnen
Level 1
*


Games! Kittens! Wine!


View Profile WWW
« Reply #4 on: April 24, 2014, 09:54:52 PM »

Nice article, yet I doubt object creation is that problematic with a modern JVM. Especially short lived objects usually should not affect performance, see http://programmers.stackexchange.com/questions/149563/should-we-avoid-object-creation-in-java

Relevant thread: http://forums.tigsource.com/index.php?topic=22054.0

And yet it did make a difference, as the spikes in frame times went away...
Logged

Chromanoid
Level 10
*****



View Profile
« Reply #5 on: April 24, 2014, 10:26:37 PM »

I see. I hope this will change in future versions of the HotSpot compiler. This "short-lived objects don't matter" thing is preached for a while now -.- For stuff like Vector calculations where you throw away the object after leaving the method scope you might want to have a look at JStackAlloc.
Logged
Julien
Level 2
**


View Profile
« Reply #6 on: April 25, 2014, 02:38:11 AM »

It might be irrelevant, or specific to Dalvik, but in the google dev doc it is recommanded to use the enhanced for each loop. Yet this article recommand the opposite. Honestly I've used both in my game and didn't mesured any difference.

I came to get(i) because of the same reason, iterators, but the comment in the google doc always troubled me.

Logged

MontyOnTheRun
Level 0
*


View Profile
« Reply #7 on: April 25, 2014, 06:20:11 AM »

Julien, I remember reading this and changing my code base to comply with it. Gains were modest, but visible. I don't have numbers now, but I would say it jumped from something like 18 FPS to 20 FPS.
Logged
Julien
Level 2
**


View Profile
« Reply #8 on: April 29, 2014, 12:06:55 AM »

Thanks for your feedback ! Smiley
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic