Routing core made once, list orders kept, and Auto-TE's detour searches cut: same routing, much less work
The game plays exactly as before. * The core of compute() (rankPass, directPass, sendGroup, send, push, carry, altPath) is ROUTE in 29-route-core.js, built once by routeCore(): made inside compute() they were new functions every call and V8 threw away their code. Exits are read by number from typed columns (USED, CAPX, CIX, HPX, VISX), each list is an object of one shape. * The route cache keeps, for each list and source city, the order routing tries it (xOrder()); a list whose exits, cities and preferences are unchanged on the same graph keeps its orders when other exits change (rcExitKeep()). * Auto-TE: pairs with no detour are marked (TEF), exits that cannot help are skipped (dud()), one failed search answers the next ones, dijkstraTo() searches in arrays kept between calls, teSearch() runs on the graph as flat arrays and picks up where the last search from the same POP stopped. * The PNI/IX tie-break (#298) reaches the core. Tests: route-cache, routing-reference, speed (the fast core against the plain path, Auto-TE on crowded meshes with POPs outside the core, picked-up searches counted).
This commit is contained in:
parent
d03dde6fcd
commit
1edf0abb54
10 changed files with 409 additions and 159 deletions
|
|
@ -181,10 +181,20 @@ them. Only indices are kept: exits, lists and paths are made fresh every call, b
|
|||
`scripts/route-fuzz.js` plays hundreds of random seeded games on main's page and this checkout's at once, comparing all
|
||||
of R and S after every move and day, with the kept tables and without (`tests/route-fuzz.test.js` plays a few).
|
||||
|
||||
Each loop of `compute()` runs in a function of its own (the stages are closures, the busiest is `rankPass`;
|
||||
the money is `computeMoney()`). V8 optimises a small function quickly and keeps it; `compute()` as one 33 KB function
|
||||
never stayed optimised: it ran in baseline code, boxing every number, and was compiled again and again in the background
|
||||
only to be thrown away, which cost more CPU than the routing itself. Keep it that way: a new loop goes in a function.
|
||||
Each loop of `compute()` runs in a function of its own (the money is `computeMoney()`). V8 optimises a small function
|
||||
quickly and keeps it; `compute()` as one 33 KB function never stayed optimised: it ran in baseline code, boxing every
|
||||
number, and was compiled again and again in the background only to be thrown away, which cost more CPU than the routing
|
||||
itself. Keep it that way: a new loop goes in a function.
|
||||
|
||||
The routing core, the loops that place every flow on an exit (`rankPass`, `directPass`, `sendGroup`, `send`, `push`,
|
||||
`carry`, `altPath`), lives in `ROUTE` (`29-route-core.js`), made once at load: `compute()` hands it the day's state
|
||||
(`ROUTE.nodes()`, `ROUTE.run()`). Made inside `compute()`, as they were, they were new functions every call, and V8 threw
|
||||
away the code it had compiled for the old ones. The core reads exits by number from typed columns (`USED`, `CAPX`, `CIX`,
|
||||
`HPX`, `VISX`), and each list as an object of one shape (`lx()`). For each list and source city, the route cache also
|
||||
keeps the list in the order routing tries it (`xOrder()`: by preference, then distance, a stable sort): on a day the cache
|
||||
is used, a flow's first group is where that order starts, past the exits that filled up, instead of a scan of the whole
|
||||
list, and what is left needs no sort. Auto-TE marks the pairs that have no detour (`TEF`), the answer to most of its
|
||||
asks. `tests/day-steps.test.js` and the routing equivalence tests hold all this to the same results.
|
||||
|
||||
Served share per city (`sfOf`) drives eyeball revenue and customer mood.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue