Routing skips paths that are already full and finds the nearest exit in one scan

Capacity only shrinks while traffic is routed, so a path with one full link
or node fits nothing for the rest of the pass: push marks it and later tries
return at once (92% of pushes on the big network went into such paths). The
nearest group of exits is found in one scan instead of two, and exits that
filled up are dropped from the shared lists once a quarter of a list is full.

Routing results are identical to before. The speed test's plain path now also
runs without these, with Auto-TE and with a RouteScript that keeps headroom on
every link; planted bugs in each of the three are caught.

Big network vs main, two runs: headless routing -51% to -58%, Chromium
desktop -22% to -31%, Chromium phone -15% to -29%.
This commit is contained in:
Frederic Jung 2026-10-26 12:35:15 +01:00
parent c76dd4d556
commit 2c0d69379a
No known key found for this signature in database
3 changed files with 26 additions and 10 deletions

View file

@ -2001,9 +2001,12 @@ function compute(){
let f=null,Dv=null,Pv=null,PP=null,vis=0;const walked=[],G=[],NEG=[];
// An exit the flow can still try: not visited yet, not full when the flow started, and reachable from the POP.
const usable=e=>e.vis!==vis&&e.used<e.cap&&Dv[e.ci]<Infinity,byDist=(a,b)=>a.hp-b.hp||Dv[a.ci]-Dv[b.ci];
// Push up to `want` along one path to exit e; returns what fitted.
const push=(e,P,want,keep=0)=>{const path=P.path,ni=P.ni;let amt=want;
for(const l of path)amt=Math.min(amt,l.res-l.cap*keep);for(const i of ni)if(HAS[i])amt=Math.min(amt,NRES[i]);
// Push up to `want` along one path to exit e; returns what fitted. Capacity only shrinks while routing, so a
// path with one full link or node fits nothing for the rest of this pass: mark it, and later tries cost nothing
// (most tries are into paths that filled up earlier).
const push=(e,P,want,keep=0)=>{if(P.dead)return 0;const path=P.path,ni=P.ni;let amt=want;
for(const l of path){const r=l.res;if(r<=1e-6){P.dead=1;return 0;}amt=Math.min(amt,r-l.cap*keep);}
for(const i of ni)if(HAS[i]){const r=NRES[i];if(r<=1e-6){P.dead=1;return 0;}amt=Math.min(amt,r);}
if(amt<=1e-6)return 0;
for(const i of ni)if(HAS[i])nodeTake(i,amt);
const ek=e.ek,nr=f.nr,ci=f.ci;if(!e.told||e.dup){R2.egDesc[ek]=e.desc;e.told=true;}
@ -2040,9 +2043,15 @@ function compute(){
G.length=0;
if(!lst.hi&&ALONE[f.ci]){const here=lst.at.get(f.ci);if(here)for(const e of here)if(e.used<e.cap)G.push(e);}
if(!G.length){
let bh=2,bd=Infinity;for(const e of lst)if(e.used<e.cap){const d=Dv[e.ci];if(d<Infinity&&(e.hp<bh||(e.hp===bh&&d<bd))){bh=e.hp;bd=d;}}
// One scan: the best (preference, distance) so far and, in list order, the exits within 1e-6 of it. The best
// distance only goes down, so dropping the ones it leaves behind gives exactly the exits a second scan would.
// Exits that are full stay full for this pass: when a quarter of a list is, it is rewritten without them.
let bh=2,bd=Infinity,full=0;
for(const e of lst){if(e.used>=e.cap){full++;continue;}const d=Dv[e.ci];if(d===Infinity)continue;const h=e.hp;
if(h<bh){bh=h;bd=d;G.length=0;G.push(e);}
else if(h===bh){if(d<bd){bd=d;let k=0;for(const x of G)if(Dv[x.ci]-d<1e-6)G[k++]=x;G.length=k;G.push(e);}else if(d-bd<1e-6)G.push(e);}}
if(full*4>=lst.length&&full){let k=0;for(const e of lst)if(e.used<e.cap)lst[k++]=e;lst.length=k;}
if(bh>1)continue;
for(const e of lst)if(e.hp===bh&&e.used<e.cap){const d=Dv[e.ci];if(d<Infinity&&d-bd<1e-6)G.push(e);}
if(G.length>1)G.sort(byDist);}
sendGroup(G);
if(f.rem<=1e-6)continue;