bsergent / overmorrow

Typescript canvas game engine
http://challengercity.com/v4/projects/overmorrow/
0 stars 1 forks source link

Heap memory fills far too quickly #43

Closed bsergent closed 6 years ago

bsergent commented 6 years ago

As seen in the profile below, the rendering freezes every second or so whenever the garbage collector runs. I believe this is due to all the primitives constantly being newed to be passed around between functions (such as draw() taking new Rectangles all the time). This could be fixed with some primitive factories that store references to old objects and reuse them instead of always constructing more.

image

bsergent commented 6 years ago

This likely only showed up due to the huge amount of Rectangles allocated by the WorldSandbox class while drawing its tiles.

bsergent commented 6 years ago

Never mind, this was also a problem before any of the WorldSandbox and DemoDungeon changes. I tried replacing all the new'ing of the primitives such as Rectangles, Vectors, and Colors, with my own new's and disposals on my own heap, leading to a variable reuse of about 70%, but the freeze every second still occurred. The heap storage was much lower, down from 22MB to 10.9MB when it got cleared. However, the garbage collection still occurred every second, not just when the memory reached a limit. So, either the garbage collection really is causing the freeze, and I'll have to find some way to minimize new allocations even more, assuming that it will always happen every second and needs to do as little as possible when it runs; or, the problem is somewhere else and the garbage collection every second is a coincidence. Maybe converting to WebGL would help? The nodes from the Canvas API do keep accumulating. It's gotta be the memory though; that's too much of a coincidence.

Edit: See https://developers.google.com/web/tools/chrome-devtools/memory-problems/.

bsergent commented 6 years ago

So apparently this problem is entirely non-existent in Edge and Firefox...

bsergent commented 6 years ago

Pack it up, boys. We're done here. It was just because I had a million tabs open in Chrome. No actual bug.