Commit graph

22 commits

Author SHA1 Message Date
Antoine
1edf0abb54
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).
2026-11-07 23:51:35 +01:00
Frederic Jung
f303f29f22
PNIs and IX ports are both peering: traffic leaves at the nearest one (#298)
Routing tried every PNI (rank 1) before any IX port (rank 2), like a
local-pref above peering, so a PNI in London pulled New York's traffic
across the Atlantic even with the same network at the New York IX. PNIs
now route at rank 2 with the IX ports, nearest first. At the same distance
the PNI goes first: an IX port counts as PNI_TIE (0.001) further away,
far below any link weight (at least 1). Distances compare as
(Da-Db)+(dta-dtb) so exits at one distance stay exactly equal, and the
POP-local shortcut skips lists that mix PNIs and IX ports. Backup only and
RouteScript's prefer pni keep their say. The traceroute, the reference
allocation in the tests and the RouteScript help follow.
2026-11-06 06:31:21 +00:00
Antoine
fca11b39d2
fix(map): drop the last network's floaters when another one starts
Floaters ("New POP!", payday money) live in FLOATS and fade on the map's
animation clock, which only runs while the game does. A new network
whose clock stands still (the agent's clock on the development page)
kept the previous network's floaters frozen over its map until a reload:
hundreds of them after a payday on a big network at 8x.

Each floater now records the network that raised it, and the map drops
any that belong to another one (new game, another slot, import, puzzle,
title screen). Same code for the 2D and WebGL maps.
2026-11-05 21:40:13 +01:00
Frederic Jung
dd6e4f4f8a
Fix CodeQL code-scanning alerts
- Values pasted into eval'd or inline-script code go through lit() (scripts/lib/js-literal.js), which escapes <, >, /, U+2028 and U+2029 after JSON.stringify
- build test and i18n-check read script tags with a DOM parser or a plain search, not HTML regexes
- mcp.js parses the Authorization header without a backtracking regex
2026-11-05 21:24:26 +01:00
Antoine
cf9ab5e774
Draw the map with WebGL2 by default, with the 2D canvas as fallback
- Sea, land, waves, clouds, cables, tubes and packets are drawn by the
  graphics card; the land is geometry built once, so panning and zooming
  repaint nothing.
- Cities, labels and markers are painted once into a sprite atlas and drawn
  in one call (with drawImage in 2D, which speeds up the 2D map too).
- Settings > Map drawing: Auto or Always 2D, per device. Browsers without
  WebGL2, a lost context and puzzles keep the 2D map.
- npm run bench:gpu compares 2D and WebGL in a real browser on a real GPU;
  ?fps shows a frame meter.
2026-11-04 22:37:12 +01:00
Frederic Jung
add3d67e48
Merge perf/6-routing-design: routing keeps its structural tables and runs as small functions, about half the CPU, identical results (347 fuzzed games)
# Conflicts:
#	CHANGELOG.md
2026-11-01 21:57:08 +01:00
Frederic Jung
d93d598d01
Tests count calendar months, not 30 days (#257) 2026-11-01 19:27:01 +01:00
Frederic Jung
85e62f6392
Routing adds up per-kind traffic in typed arrays and keeps its group array's storage: half the allocation per compute
R.egT and R.netEg were summed by key in push(), which boxes every new value; they are now Float64Array sums written
back after routing, in the same order and key order. The first group G was emptied with length=0 for every flow,
which gives back its storage so the next push allocates it again; it is now G[0..GN). 27.5 MB -> 13.5 MB per compute.
2026-11-01 19:04:17 +01:00
Frederic Jung
a428ed817f
Routing keeps its structural tables between calls and runs its hot loops as small functions, identical results
compute() was one 33 KB function that V8 never kept optimised: it ran in baseline code, boxing every number,
and was recompiled in the background (about a second of compile each time on a loaded machine) only to deopt.
Its stages now run as closures of their own (compute's own bytecode: 7.7 KB) and the money is computeMoney().
The shortest paths and the exit lists (okBy, reach, BRJ/LIST, DSEL) are kept between calls under keys built
from everything they depend on (29-route-cache.js). Exits and paths have one object shape each.
The equivalence tests compare cached against uncached routing; tests/route-cache.test.js checks the keys.
2026-11-01 19:04:17 +01:00
Frederic Jung
b6c2fe677b
Speed test: switch off the routing shortcuts in their new spelling (flows are columns now) 2026-11-01 15:34:42 +01:00
Frederic Jung
70676d7bfb
Backbone technology: plain IGP, LDP, RSVP-TE, SR-MPLS, SRv6; two new RSVP-TE routers
Each router is classed by the highest backbone it runs and has a vendor. Upgrades
are paid one step at a time and any level paid for can run. Higher levels use
less router CPU, label switching makes pass-through traffic cheaper, Auto-TE and
RouteScript need RSVP-TE or above, and POPs whose routers can't run the backbone
stay outside it. Mixed vendors at the top of what their routers can do get
interop failures. Saves with Auto-TE keep the old rules; puzzles, Architect and
scenarios are unaffected.
2026-10-31 08:27:31 +01:00
Frederic Jung
4c499de742
Merge #158: smoother huge networks, map and autosave (huguesdelamure)
Capacity deals now record customer names with useName() too, and the
#156 CHANGELOG bullet moves to Unreleased where it belongs.
2026-10-27 20:43:46 +01:00
Hugues
a3dd1dd810 Busy maps: no link labels or fiber dots above 1,000 lines on screen
On a save with 2,700 lines on screen, Firefox spent about 95% of each
frame painting, and the dotted line on lit fiber (~160 ms) and the link
labels (~55 ms) were half of it, in a tangle where neither can be read.

draw() now counts the lines it would paint (linesOnScreen(), same box and
margin as its own culling, boxes cached on the geometry) and above
MAP_BUSY = 1000 leaves out both. They come back as soon as fewer lines
show, zooming in for instance. The selected link keeps its label.

Firefox Developer Edition headless, 1600x900 at DPR 2, player save, median
of 3x9 frames: save view 414 -> 214 ms, pan 472 -> 238, zoom 0.6 269 -> 181,
New York zoom 2 213 -> 107, selected link 412 -> 201. Under the threshold
pixels are identical (canvas SHA-1): zoom 3.2 and 6 on the player save, six
views of the big-network fixture.
2026-10-27 14:03:04 +01:00
Hugues
ecb862e70d 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.
2026-10-27 13:44:47 +01:00
Hugues
456062284f Faster days on big networks: look fiber customers up by link id
compute(), the daily mood check and new alien-wave/fiber-pair offers asked
S.links.find() or S.biz.filter() once per customer or per link. On a save
with 2,950 links and 18,000 customers (16,000 alien waves) that was ~150 ms
per compute, ~250 ms more per day, and ~650 ms when a wave offer spawned.

linkIds() and fiberUse() build the lookups in one pass; fiberOk, bizSf,
soldSlots, freeCh and pairFree take them optionally, and give the same
answers as before (first link with the id wins, sums in S.biz order).

Player save (202 POPs, 2,958 links, 17,967 customers), median of 15:
compute 323 -> 124 ms, dayTick 545 -> 133 ms, after 356 -> 149 ms.
Big-network fixture: unchanged. Routing results identical to main.
2026-10-27 12:26:10 +01:00
Frederic Jung
4682f16730
Routing makes far less garbage: no temporary arrays or closures in its hot loop
The group split runs over an index range with one scratch array instead of
map/reduce/forEach and slice, leftover exits go into one reused array and are
sorted in place (insertion sort for short lists; both sorts are stable, so
the order is the same), flows are split without per-flow arrays, and the hot
loops use indexes instead of for...of. Without Auto-TE, exits whose path is
already full are not called at all. One routing pass on the big network
allocates 23 MB in Chromium instead of 66 MB.

Routing results are identical. The speed test's plain path now also uses the
original group split and sort, and a new test routes around a full 10G link
with Auto-TE (and a spill script) and compares both paths; planted bugs in
the split, the sort and both full-path skips are caught.

Big network vs main, two runs: headless routing -23% to -30%, Chromium
desktop -14% to -27%, phone -15% to -27%. Steps 2-4 together vs c76dd4d:
Chromium desktop routing -49%, phone -34%, a game day -26% and -30%.
2026-10-26 13:41:13 +01:00
Frederic Jung
2c0d69379a
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%.
2026-10-26 12:35:15 +01:00
Frederic Jung
0ecce20dec
Test that #89's fast routing matches the plain path
Builds a copy of compute() with the own-exits shortcut, the first-group
scan and the per-network exit index switched off, and compares both on a
busy network with Auto-TE, preferred and backup exits, two upstreams per
city, route servers and two cache boxes per CDN. Verified it fails when
either shortcut is deliberately broken.
2026-10-26 05:56:15 +01:00
Frederic Jung
47c7c19402 Rest the map while the dashboard covers a phone screen
On a phone the NOC dashboard, scrolled past its top edge, fills the whole
screen, but the map underneath was still drawn every frame: about 4 ms per
frame on a big network on a fast PC, several times that on a phone. While a
panel covers the map completely it is no longer drawn, and it comes back as
soon as any of it shows. At the top of the dashboard the strip of map above
the card keeps moving, and on desktop, where the map shows around the
dashboard, nothing changes. No payday floaters are made while the map is
hidden, so they cannot pile up out of sight.
2026-10-26 02:00:33 +01:00
Frederic Jung
e026836169 Rest the map while paused, and fade payday floaters after a pause
- Payday floaters were stamped with performance.now() but aged with the map's
  animation clock, which stops while paused. After a pause they never faded:
  they sat off-screen and were drawn every frame, about a hundred more per
  payday on a big network, so long sessions got slower and slower. They are
  stamped with the animation clock now.
- While paused or with animations off, the map is only redrawn when the camera,
  the selection, hover or drag, the network or a new day changes it, plus once
  a second and while the land picture catches up after a zoom. A paused frame
  drops from ~4 ms to ~0.05 ms.
- After a day ends, the open panels update on the next frame, so one frame does
  not carry both the day's simulation and the panels. With a day on every frame
  they still follow, one frame behind.
2026-10-26 01:29:17 +01:00
Frederic Jung
9b1ed2f776 Show long NOC dashboard lists 100 rows at a time
The Connections tab drew every connection at once: 1,486 rows with their
buttons came to 32,000 elements, and laying them out again after every day
took about half a second while the dashboard was open (far longer on a phone).
The Connections and Customers lists now show 100 rows and a "+100 more"
button. Filters, sorting and totals still cover every row, and changing a
filter or the sort starts the list short again.
2026-10-26 00:42:37 +01:00
Frederic Jung
a887b65a2f Make big networks fast: routing, panels and map drawing
A network with a hundred POPs and a thousand peering ports froze the game for
most of a second every day and after every click, because routing checked all
~1,800 exits for each of ~14,000 flows. Now:

- compute(): exits are asked once per network which networks they reach, each
  flow scans only those, and the first ECMP group is found without sorting. The
  graph runs on city indices with a typed-array Dijkstra (same heap moves, same
  ties), routers and per-link traffic are kept in typed arrays, the diverse-path
  check reuses one live-link graph, and R.ef is put together when a link is read.
  Results are bit-identical to before.
- Panels and the NOC dashboard are patched in place (morph) instead of being
  rebuilt, so the browser no longer restyles 1,500 rows every tick. Buttons whose
  action changed are swapped out, keeping #44's tap protection.
- The Networks tab works out each IX port's sessions once instead of once per
  network.
- draw() reuses screen-point buffers, a per-frame pair index and cached label
  widths, strokes the dotted fiber line on the path it already has, and uses
  native roundRect: about a third fewer canvas calls per frame, same output.
2026-10-26 00:03:05 +01:00