Map of huge networks: fiber capacity once per frame, skip links off screen

draw() asked dfCap() three to five times per fiber link and per frame (width,
colour, label, up or down), each time over all its channels: on a save with
3,140 dark fibers of 18 channels on average that was about half of draw()'s
JavaScript. dfCap() now keeps its answers in DFC while one frame is drawn
(cleared in a finally, so a failed frame keeps nothing), and the link label is
built once per line instead of once per world copy. Links entirely above or
below the screen are skipped like those left or right of it already were.

Player save (202 POPs, 3,142 links), jsdom: draw() 40 -> 25 ms; perf-bench
"Map at three zoom levels" 89.7 -> 47.1 ms. Canvas call log identical at
every zoom without the vertical skip; Firefox pixels identical (SHA-1 of the
canvas) in 7 views. Firefox still spends ~95% of the frame painting.
This commit is contained in:
Hugues 2026-10-27 13:44:47 +01:00
parent 97b195dd91
commit ecb862e70d
4 changed files with 35 additions and 6 deletions

View file

@ -100,6 +100,27 @@ test('the map draws a big network at every zoom, with a city or a link selected'
assert.deepEqual(errors, []);
});
test('the map keeps fiber capacities for one frame only, and skips links above or below the screen', () => {
const { ev, errors } = load();
bigNet(ev);
ev("S.links.push({id:'dfT',a:'fra',b:'ams',kind:'df',own:true,km:kmBetween('fra','ams'),ready:0,ch:['zr4']});compute()");
ev('cam.x=CITY.fra.x;cam.y=CITY.fra.y;cam.z=2;draw(0)');
assert.equal(ev('DFC'), null, 'nothing is kept between frames');
const cap = ev("dfCap(S.links.find(l=>l.id==='dfT'))");
ev("S.links.find(l=>l.id==='dfT').ch.push('zr4');draw(0)");
assert.equal(ev("dfCap(S.links.find(l=>l.id==='dfT'))"), 2 * cap, 'a new channel counts on the next frame');
ev("ctx.fillText=()=>{throw new Error('boom')}");
assert.throws(() => ev('draw(0)'));
ev('delete ctx.fillText');
assert.equal(ev('DFC'), null, 'not even after a frame that failed');
// The whole network far above the screen: the links cost nothing, as if there were none.
const calls = (body) => ev(`(()=>{cam.x=CITY.fra.x;cam.y=CITY.fra.y+${'2000'};cam.z=2;${body};const n=ctx.calls.n;draw(0);return ctx.calls.n-n;})()`);
const withLinks = calls(''), links = ev('JSON.stringify(S.links)');
assert.equal(withLinks, calls('S.links=[]'));
ev(`S.links=JSON.parse(${JSON.stringify(links)})`);
assert.deepEqual(errors, []);
});
test('long lists in the NOC dashboard show 100 rows at a time and grow on request', () => {
const { ev, errors } = load();
bigNet(ev);