Faster Networks tab and map labels: count connections without building them, cache exchange lists, grid label check

This commit is contained in:
Frederic Jung 2026-11-01 12:40:48 +01:00
parent 5e27f9e787
commit 597cc40aef
No known key found for this signature in database
4 changed files with 18 additions and 6 deletions

View file

@ -15,8 +15,12 @@ const premCity=(n,c)=>!!n.premium&&!!n.premAt&&n.premAt.includes(c),premOnlyAt=(
const premOn=t=>!!t.premium&&!!NET[t.net]&&premCity(NET[t.net],t.city);
// What a port costs per Gbps and month before the commit: the premium crossing at Hong Kong prices, anything else at the city's.
const transitPerG=(n,c,prem)=>prem&&premCity(n,c)?n.price*n.premium*netMult(n,'hkg'):n.price*netMult(n,c);
const onIx=(n,c)=>CITY[c].au&&n.auIx?n.auIx.includes(c):n.ix==='ALL'||Array.isArray(n.ix)&&n.ix.includes(c);
function ixMembers(c){if(XIXM[c])return XIXM[c].members.slice();if(S.myIx[c])return S.myIx[c].members.slice();if(!CITY[c].ix)return [];return NETS.filter(n=>onIx(n,c)).map(n=>n.id);}
// Exchange lists are fixed once the page has loaded, so each is looked up through a Set built on first use.
const IX_SET=new WeakMap(),inIxList=(a,c)=>{let s=IX_SET.get(a);if(!s)IX_SET.set(a,s=new Set(a));return s.has(c);};
const onIx=(n,c)=>CITY[c].au&&n.auIx?inIxList(n.auIx,c):n.ix==='ALL'||Array.isArray(n.ix)&&inIxList(n.ix,c);
function ixMembers(c){if(XIXM[c])return XIXM[c].members.slice();if(S.myIx[c])return S.myIx[c].members.slice();if(!CITY[c].ix)return [];return (IX_MEM[c]||(IX_MEM[c]=NETS.filter(n=>onIx(n,c)).map(n=>n.id))).slice();}
// A city exchange's members only depend on the networks, which are fixed after load.
const IX_MEM={};
// LAG: several identical ports bundled into one logical link. Flow hashing is never perfectly even, so a bundle carries ~95% of the sum.
const LAG_MAX=8;
function lagCap(g,n){n=n||1;return g*n*(n>1?0.95:1);}