Last night I worked on eliminating all memory allocations in the hot code areas to get rid of the disturbing garbage collection calls.
GcodeSimulator has two major loops (visualisation and printer control) which iterate over thousands of gcodes and therefore should never allocate memory while running.
When running in simulation mode with 99x speedup I measured the following:
Garbage collection is triggered every 20sec to collect up to 2MB objects!!!
I figured out that some of the enhancements I did where contra productive e.g. reuse of a Stringbuilder - clearing it creates a new array.
Also integer to string (display xy speed,…) and float to string (display z position) conversion created many temporary objects.
After replacing the jdk converters with my own implementation and replacing the stringbuffer with a global char array no allocations happen anymore (just at the beginning before the first layer starts.)
Result: running for longer time in simulation mode with 99x speedup does not cause any garbage collection.
Next step is to optimize the printer loop …