2D map: hold its pictures to 48 MB, letting go of those unused the longest

The 2D map keeps a canvas per picture, and the list was capped only by its length (1 400). A long zoom on a big
network paints every city again at each step of its scale, so a pinch from 0.6 to 3.2 and back held 181 MB of
pictures (the TTL save: 179 MB) where one frame uses 2 to 23 MB.

At the end of a frame over 48 MB, the pictures it did not use go, those unused the longest first, down to 36 MB, and
each canvas let go is emptied (0×0) so its pixels are freed without waiting for the collector. The frame's own
pictures are never let go, so a screen that needs more keeps what it needs. Finding a picture now marks it as used.

Measured in jsdom on the same pinch (1280×800 at 2×): 43 MB at most (TTL: 40 MB); 4 781 pictures painted against
4 083 (TTL: 5 549 against 6 030); at most 321 painted in one frame, the same as before (the zoom's own steps).
The card's atlas is unchanged: it has its own fixed size.
This commit is contained in:
Antoine 2026-11-05 00:00:34 +01:00
parent d57b3ae10f
commit 57546ea18e
No known key found for this signature in database
GPG key ID: 728FF1CE15732B05
3 changed files with 88 additions and 7 deletions

View file

@ -1,8 +1,8 @@
/* A frame. An error from the card itself (glErr()) gives WebGL up for this session and draws the same frame again in
2D, once; any other error goes on to the loop's tickErr(). Either way the 2D context and the sprite queue are reset. */
function draw(now){for(let pass=0;;pass++){let err=null;DFC=new Map();
function draw(now){for(let pass=0;;pass++){let err=null;DFC=new Map();SPR_F++;
try{drawFrame(now);}catch(e){err=e;}
try{glsFrameEnd();}catch(e){if(!err)err=e;}finally{DFC=null;GLS.frame=false;GLS.n=0;ctx=CTX0;}
try{glsFrameEnd();}catch(e){if(!err)err=e;}finally{DFC=null;GLS.frame=false;GLS.n=0;ctx=CTX0;sprcTrim();}
if(!err)return;if(!err.glErr||pass)throw err;glKill(err);}}
// Rectangles on a 64 px grid: a new one is compared only with the few that share its cells (a plain list made the
// label placement quadratic in the number of cities).