Garbage Collection: The Magic Number is 6

I read a fascinating article recently on why mobile apps are so slow – the article is well worth the peruse as to why JavaScript apps will never keep up to C/C++ (note this also affects most interpreted languages like Python, Ruby, Java, VB.net/C# etc).

But the main point I remembered is the magic number for garbage collection: Six times the used memory. Or to put it another way, as long as you keep your program’s memory usage under 1/6 of available memory, life is good (I’m referring to GC-managed memory of course).

But go under that – especially under 4x (or 1/4) – and it gets very bad. In fact, the function for it is exponential, and under 1/6 memory the curve starts to climb fast. In the cases he mentioned in his post, some tests took 10-15 times as long to run when GC was used versus regular memory management.

This isn’t surprising of course: I programmed the Commodore 64 which had string garbage collection, and you soon got a feel for how many strings you could handle. Too many, and the computer abruptly halted while it cleaned them up. Today, however, most programmers on desktops never hit a performance issue, since 1/6th the memory is a LOT of strings or other data. But on small devices that 1/6 comes up quickly…

Morale of the story: Enjoy your Java, but never forget your malloc() and new[] – and be sure you remember ‘6’ while you craft your next Java app…

SOME ITEMS YOU MIGHT ENJOY
OEM Arduino board model MEGA 2560
$42.00
End Date: Thursday Jan-11-2018 9:17:21 PST
Buy It Now for only: $42.00
Buy It Now | Add to watch list
ATMEGA16U2 Board For Arduino Mega 2560 R3 Board Kit Compatible With USB Cable US
$10.63
End Date: Wednesday Jan-10-2018 20:00:28 PST
Buy It Now for only: $10.63
Buy It Now | Add to watch list
Ultimate Starter Kit UNO R3 Arduino LCD Stepper Servo Ultrasonic Motor 1602
$35.46
End Date: Wednesday Jan-10-2018 12:57:36 PST
Buy It Now for only: $35.46
Buy It Now | Add to watch list


Leave a Reply

Your email address will not be published. Required fields are marked *