visualization-tool
visualization-tool copied to clipboard
Page gets very slow after some time (memory leak?)
Not sure how feasible this is to fix but should be investigated. If a page is open for a long time, it tends to get very slow until refreshed.
There is a memory leak! I can't seem to recreate the slowness issue to confirm that my solution does anything to help😅 but the memory issue does exist.
The problem is that in many visualizations the value of nextIndex
continues to grow infinitely. It's more problematic on algorithms than data structures, because with DS each operation adds a small constant amount to nextIndex
but with algorithms it adds a larger amount proportional to the input size.
And the issue obviously isn't just the integer nextIndex
, but what it represents which is the label # of the next animated object. At any time there is an array of animated objects being stored in this.animationManager.animatedObjects.nodes
, and as nextIndex
grows so does the array. This leads to potentially hundreds of empty indices in the array each time the algorithm is run, which grows to thousands over time.
One solution that's already (sort of) being used in some visualizations is a "reset index", that allows for some constant objects to avoid be reinstantiated and resets nextIndex
each time the algorithm is re-run.
Here's an example of that idea being implemented in Quicksort
Is there any particular vis where you noticed performance issues? We could test this fix there first
I noticed it on algorithms like you said. On LSD Radix Sort, it happened during Dr. HB's lecture. I think she had the page up for a while off-screen, then when she pulled it up to demonstrate something, it was extremely slow. But what's curious is I don't know if repeatedly running the algorithm is the only cause - it seems like it just happens if you leave the page open for a while in the background? I'll try and see if I can replicate it by doing that.