Skip to content

perf(analytics): DAGI choropleth draws in half the time, same paths (#1002 M3) - #1091

Merged
dborup merged 2 commits into
masterfrom
fix/1002-m3-choropleth-perf
Dec 2, 2026
Merged

dborup merged 2 commits into
masterfrom
fix/1002-m3-choropleth-perf

Conversation

@adminopenclaw8-sketch

@adminopenclaw8-sketch adminopenclaw8-sketch commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Relates to #1002

Why

Master CI is red: the M3 E2E step "perf: decode + draw at a plain 4x CPU throttle, 375x560, <= 250 ms" fails on ebfa4ff5 (run 46862438147: postnummer 309.6 ms) and on #1088's merge run (322.1 ms).

It is not a code regression. The step was always close to the budget on CI, and the runner got slower:

Run Commit kommune postnummer
#1071 CI 6fcba31c 120.2 227.0
#1071 CI 51241991 121.9 218.8
#1071 CI f5f14f71 108.0 197.7
#1071 CI a7612474 114.0 208.2
master (red) ebfa4ff5 169.8 309.6
#1088 CI (red) 4163cf54 (head) 173.7 322.1
local A/B, 3 rounds a7612474 53–56 107–111
local A/B, 3 rounds ebfa4ff5 53–55 107–109
  • Decode and draw both went up by about 1.5× (decode 23 → 32–35 ms), for both layers.
  • Across all 62 shard-2 suites, wall time was a median 1.23× longer in both red runs. The two green runs agreed with each other within 2%. So the whole shard ran slower, not only this suite.
  • CI gave 198–227 ms against the 250 ms budget, only 10–20% headroom.

The budget and the throttle are unchanged. This PR makes the draw faster instead.

What

A CPU profile at 4× showed no single hotspot. The time went to Leaflet's per-vertex work on 44,487 vertices: converting them, recomputing bounds, projecting, clipping and garbage collection. It also went to per-layer setup for 605 shapes: tooltips and SVG paths.

The choropleth now uses its own subclasses of L.Polygon and L.FeatureGroup (shapeClasses(L) in dagi-choropleth.js). They draw the same paths:

  • DagiFilter.decodeRings(resp, vertex): an optional vertex factory, so the decoder makes Leaflet's own LatLngs. The shape keeps them along with the decoder's bounds, so there is no second per-vertex conversion. The default output ([lat, lon]) is unchanged for Map, Live and Packets.
  • Projection produces the same points in the same order as latLngToLayerPoint (project, transform at the zoom's scale, round, subtract the pixel origin). It just skips the per-vertex scale and origin lookups.
  • There is no clipping pass for a shape that lies inside the clip box. In that case Leaflet's clipper returns the same points anyway. Partly visible shapes still go through Leaflet's clipper.
  • There is one sticky tooltip on the group instead of 605. aria-describedby goes only on the shape under the pointer, as before. Leaflet's focus listeners stay on every shape, so the shapes remain in the keyboard Tab order and a tapped shape keeps its focus ring, as on master. Clicks stay per shape.

Local timings at 4×, 375×560, best of 3:

master this PR
kommune 55–58 ms 32–34 ms
postnummer 109–114 ms 59–62 ms

Tests

  • E2E, new step: draws every kommune and postnummer area with both L.polygon and the choropleth's Shape on one map, then compares every path's d attribute. It checks the fitted view, Aarhus at z11, København at z13, fractional zooms Aarhus z9.25 and Fanø z11.75 (zoomSnap 0.25), and a Skagen (9493) z8.5 sweep that puts each side of its box -3 to +3 px over the clip box edge. Result: 0 differ. Asserts that the zoomed views do clip shapes.
  • E2E, Tab and focus (review F1): Tab from "Hide map" goes to the map, then the first three shapes, each with aria-describedby and the tooltip open; a clicked shape takes the focus.
  • E2E, desktop step: the single tooltip names Aarhus, then Odense under the pointer; one tooltip is open; only those two shapes carry aria-describedby.
  • Unit: decodeRings(resp, vertex) gives the same numbers, order and bounds as the default. Shapes keep the decoder's LatLngs and bounds. The decoder's rings never repeat their first vertex (0 of 3,095), so the closing-vertex branch is gone. There is one sticky group tooltip and none per shape. tests/fake-leaflet.js gained LatLng, Polygon.extend and FeatureGroup.extend.
  • Mutants killed: projection without rounding, clipping always skipped, and aria-describedby on every shape. Rounded zoom, a 3× clip tolerance and the focus no-op put back now die too (the first two in the identity step, the last in the Tab step).
  • sh test-all.sh: 407 passed. node scripts/run-e2e-shard.js --validate: OK. M3 E2E: 10/10. M1, M2 and Backlog: place names, DAGI region filter and km² coverage from Klimadatastyrelsen data #740 M3b DAGI E2E suites: green.

Perf justification (rule 0)

This is the hot path of the "Show map" tap: O(vertices) in a single pass, with no extra passes added. Allocations go down: one LatLng per vertex instead of an array plus a LatLng, and no clip arrays for shapes that are inside. The number of DOM elements is unchanged.

🤖 Generated with Claude Code

#1002 M3)

Master CI went red on the M3 perf step (postnummer 309.6 / 322.1 ms >
250 ms at 4x). Not a code regression: a761247 and ebfa4ff measure the
same locally (107-111 ms), and every shard-2 suite ran ~1.23x slower in
both red runs. The step had 10-20 % headroom on CI (198-227 ms).

The choropleth now uses Leaflet's Polygon and FeatureGroup minus work it
does not need, drawing the same paths:
- decodeRings(resp, vertex) makes Leaflet's own LatLngs, and the shape
  keeps them and the decoder's bounds (no second per-vertex conversion);
- projection makes the same points as latLngToLayerPoint without the
  per-vertex scale and pixel-origin lookups;
- no clipping pass for a shape inside the clip box (the clipper returns
  the same points there);
- one sticky tooltip on the group instead of one per shape, and no focus
  listeners on SVG paths, which Leaflet never makes focusable.

Locally at 4x, 375x560: postnummer 107-110 -> 54-57 ms, kommune 54 -> 31
ms. A new E2E step compares every path's d with L.polygon's on one map,
fitted and zoomed in (clipped), kommune and postnummer: 0 differ.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adminopenclaw8-sketch

Copy link
Copy Markdown
Collaborator Author

Rapport — CS-Macmini PR#1091 #1002 M3 perf — head 1bceb03

Status: The red master step is not a code regression. It is a perf budget that had only 10–20% headroom on CI, run on a slower runner. This PR halves the choropleth's decode + draw locally (postnummer 107–110 → 54–57 ms at 4×) and cuts it by 30% on CI (210 → 145.5 ms). The drawn paths are byte-identical to L.polygon's. The budget (250 ms) and the throttle (4×) are unchanged. CI is green on all jobs on the first run. The PR is a draft, waiting for review.

Evidence tags: [T] test or command run locally, [A] reasoning or assumption, [K] CI on GitHub.

1. Regression or always close? Measured times

Run Commit kommune ms postnummer ms Result
[K] 46708240352 (#1071) 6fcba31c 120.2 227.0 ✓
[K] 46731135758 (#1071) 51241991 121.9 218.8 ✓
[K] 46816779913 (#1071) f5f14f71 108.0 197.7 ✓
[K] 46836849395 (#1071) a7612474 114.0 208.2 ✓
[K] 46862438147 attempt 1 (master) ebfa4ff5 169.8 309.6 ✗
[K] 46863259514 (#1088) 4163cf54 173.7 322.1 ✗
[K] 46862438147 attempt 2 (master, failed jobs re-run) ebfa4ff5 116.0 209.6 ✓
[K] 46883900518 (this PR) 1bceb036 82.4 145.5 ✓
  • [T] Local A/B, same machine, same test file, alternating 3 rounds: a7612474 gave postnummer 107.4–110.7 ms and ebfa4ff5 gave 107.4–108.9 ms. No difference.
  • [K] In both red runs, every shard-2 suite was slower: a median 1.23× in wall time across 62 suites, against 0.98× between the two green runs. Decode, which is pure JS and touches no DOM, also went up by 1.5× (23 → 32–35 ms). That points to the runner, not the code.
  • [K] Re-running the same master commit without changes gave 209.6 ms (green). Master is green again on ebfa4ff5, attempt 2.
  • Conclusion: there is nothing to bisect. The test was always at 198–227 ms on CI, against a budget of 250 ms.

2. Profile (4×, 375×560, postnummer: 605 shapes, 2,183 rings, 44,487 vertices)

  • [T] The CDP CPU profile shows throttling as (program), so phase marks inside draw() were used. On master that gave: shape loop 31 ms (L.polygon 22, bindTooltip 5.5); fitBounds → map load 70 ms (projection 20%, SVG _initPath 20%, tooltip focus listeners 12.6%, tile layer 9%, simplify 8.6%, clipping); GC about 20 ms.
  • [T] Leaflet 1.9.4 leaflet-src.js was swapped in through a Playwright route (SRI stripped, local only) to get readable function names.

3. Changes and their measured effect (local, 4×, postnummer work)

Step Change ms
— master 108
A decodeRings(resp, vertex) makes L.LatLng (no second conversion) 99
B No clipping pass when the shape lies inside the clip box 93
C No focus listeners on SVG paths (Leaflet never makes them focusable) 87
D One sticky tooltip on the group instead of 605 82
E The shape keeps the decoder's LatLngs and bounds (no per-vertex extend) 77
F Projection without the per-vertex scale/getPixelOrigin/toLatLng calls, same arithmetic 66
— Final, measured in the M3 E2E itself (without phase marks) 54–57

Not done: a canvas renderer (it changes the DOM the suites click and read, and moves the drawing out of the measured window), pre-simplifying the geometry (changes the drawing when zoomed in), and moving the tile layer's first view out of the draw.

4. Tests

# Requirement Test Red before Mutant(s)
1 The drawing is unchanged E2E "the choropleth's shapes draw exactly what L.polygon draws": every path's d on one map, fitted, Aarhus z11 and København z13, kommune and postnummer. [T][K] 0 differ in 6 views; 4/17/3/10 shapes cut by the clip box [T] red on master (shapeClasses missing) killed: no _round() (99 differ); clipping always skipped (99 differ)
2 The single tooltip names the shape under the pointer, and only that shape is marked as described E2E 1440×900: Aarhus → Odense, 1 tooltip, aria-describedby only on 0461 and 0751 [T] passes on master too (behaviour guard) killed: aria-describedby on every shape (99)
3 The decoder's vertex factory gives the same numbers and bounds test-issue-740-m3b-dagi-packets-map.js [T] red —
4 Shapes keep the decoder's LatLngs and bounds; one group tooltip, none per shape test-dagi-choropleth.js (2 new, 2 updated) [T] 4 red —
5 Budget the existing perf step, unchanged — survives: focus listeners on the group (speed only, never output)

Rules

Rule Result
Budget/throttle unchanged [T] PERF_BUDGET_MS = 250, CPU_THROTTLE = 4 not touched
No server change [T] cmd/ and .github diffs are empty
XSS gate [T] scripts/check-xss-sinks.sh --diff origin/master exit 0; [K] preflight green
No hardcoded colours [T] 0 hex values added
Commit identity [T] dborup <kontakt@meshview.dk>, one commit, explicit git add

Local runs

Open points for the owner

  • [A] Margin on CI after the fix: 145.5 ms on a normal runner. On a runner as slow as in the red runs (about 1.5×), that is roughly 220 ms, still under 250, but not by much. If more margin is wanted later, the remaining options are: the tile layer's first view outside the draw (about 9% of fitBounds), a canvas renderer, or a different budget/throttle, which is the owner's call.
  • [A] The overrides use Leaflet's private methods (_setLatLngs, _projectLatlngs, _clipPoints, _addFocusListeners, _setAriaDescribedByOnLayer). Leaflet is vendored and pinned at 1.9.4 with SRI, and the identity E2E fails if a Leaflet upgrade changes the output.

@dborup

dborup commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Review — CS-VM1 PR#1091 — head 1bceb03

Dom: REQUEST CHANGES

The drawing claim holds, and I checked it more thoroughly than the PR's own test does. I compared master against this PR on the real Analytics map: 120 views, 33,984 path records, 0 differ. The optimisation is sound, there is no leak, and the decode + draw speed-up is real. The PR is held back by one behaviour change it does not announce. Its stated reason is also wrong. Every choropleth shape leaves the keyboard Tab order in Chromium, and a tapped shape no longer gets its focus ring. The fix is one line, or an explicit owner decision (F1). Everything else is a nit.

Evidence tags: [T] tested here (linux/amd64, Chromium from Playwright, merged tree e618ede1 = origin/master 61d8e5e4 + head); [A] reading or reasoning; [K] CI on GitHub.

Findings

# Severity Finding Evidence
F1 Blocking (unannounced behaviour change) The Group._addFocusListeners no-op takes every shape out of the keyboard focus order. On master, Tab from "Hide map" goes map → path 0101 → 0147 → 0151 … through all 99 kommune shapes (605 for postnummer). Focusing a shape opens its tooltip (name + value) and sets aria-describedby. A tap or click leaves the browser's focus ring on the shape. On this PR, Tab goes map → zoom in → zoom out → attribution link → the table's sort buttons, and a tapped shape shows no ring. The PR's reason is wrong: "No focus listeners … on SVG paths, which Leaflet 1.9.4 never makes focusable". Leaflet adds no tabindex (path.tabIndex === -1 on both), but Chromium makes an SVG element focusable once it has focus listeners. The author's surviving mutant, "focus listeners put back on the group survives: it only affects speed", is therefore a behaviour change, not a speed-only one. [T] focus.js master vs PR (Tab sequence, activeElement after a click); [T] screenshots 375×560: master shows the focus ring around Odense after the tap, the PR does not; the fresh-map screenshots are otherwise byte-identical
F2 Minor (test gap) The identity step only checks integer zooms (fitted at 375×320, z11, z13). My mutant A, crs.scale(Math.round(m.getZoom())), passes it with "0 differ" in all 6 views. Only the desktop tooltip step happens to kill it, because Aarhus/Odense cannot be found at z6.5. The app uses zoomSnap: 0.25 and fits desktop at z6.5. [T] mutant A run of the M3 E2E
F3 Minor (test gap) The clip fast path's tolerance boundary is not covered. My mutant B (3 * w instead of w on all four sides) passes the PR's E2E. My before/after harness catches it: 1 path differs at a map edge (postnummer 9493, Skagen z8.5, 375×560). [T] mutant B: PR E2E green, cmp-paths.js 1 differ
F4 Nit Shape._addFocusListeners: function () {} is dead code, because shapes never bind a tooltip (only the group does). The closing-vertex branch in Shape._setLatLngs never runs on real data: 0 of 3,095 rings repeat their first vertex, and mutant E (no drop) survives everything. It is harmless parity code, but neither part is tested. [A] + [T] data scan, mutant E
F5 Info With one shared tooltip, hovered shapes collect aria-describedby pointing at that one tooltip id. On master each pointed at its own tooltip, which was removed once it closed. Both are stale after close, so it does not matter much while the paths are not focusable. With F1 option (a) it behaves like master per focused shape. [T] lifecycle.js (described)
F6 Info On this test machine the 4× perf step fails for master and the PR alike: the VM is roughly 25–60× slower than the author's machine and CI. M2's table perf step also fails here on master with the PR not touching it (1938 ms). The 250 ms budget therefore cannot be checked here in absolute terms, only A/B. The CI numbers in the PR (82.4 / 145.5 ms) are not independently verified here. [T] A/B below; [K] job statuses only

F1: what to do (either option closes it)

  • (a) Keep master's behaviour. Delete the _addFocusListeners: function () {}, line from Group, and preferably also the dead one on Shape.
    • I tested this as candidate G [T]. The Tab sequence is identical to master (map → 0101 → 0147 → …), focus opens the right tooltip, aria-describedby goes only on the focused shapes, and no paths change.
    • It costs part of the speed-up. In the A/B below, postnummer median goes 3171 → 4826 ms on this slow VM; master is 7566 ms, so G is still about 36% faster. The author's own profile put the focus listeners at about 12.6% of fitBounds.
    • Add an E2E step: Tab from "Show map" reaches a path.dagi-choro-shape, and its tooltip names it.
  • (b) Drop the shapes from the Tab order on purpose. There is a reasonable case for it: 605 tab stops sit in front of the table, and the table carries the same numbers.
    • This needs the owner's decision.
    • The PR text needs correcting: it should say the shapes were focusable and are no longer.
    • A test must pin the new behaviour, e.g. Tab from the map goes to the zoom control, and no path receives focus.

Answers to the questions

  1. Byte-identical paths: confirmed [T].
    • How: my own cmp-paths.js loads the real Analytics › Areas (DAGI) map from two servers, master (61d8e5e4) and the merged tree, under identical conditions (deep link, same viewport, tiles blocked).
    • What it compares: every path.dagi-choro-shape by key, on d, fill, stroke, fill-opacity, stroke-opacity, stroke-width, fill-rule, class, linecap/linejoin and pointer-events, plus the DOM order.
    • Layers: kommune and postnummer at 375×560 and 1440×900, light and dark; landsdel and region at 375×560, light.
    • Views: fitted (z6 / z6.5), Bornholm z9.25 and z11, Christiansø z13, København z13 and z15.5, Fanø z11.75, Læsø z11, Ærø z11.5, a Skagen map edge at z8.5, a 150/80 px pan after fitting (clip update without reprojection), and an animated zoom-in through the zoom control.
    • Result: 120 views, 33,984 path records, 0 differ, same order everywhere.
    • Geometry covered: 65 kommune and 163 postnummer shapes have several rings, about 1,600 rings nest inside another ring's bbox (holes, islands, enclaves), and Christiansø is included (0411 / 3740).
    • Styles: the theme toggle and the customizer restyle are covered by the dark runs and by the M3 E2E. Hover and tap give the same tooltip text as master. There is no "selected" style on the map in either version; a pick only changes the URL and the card.
    • Canvas: not applicable, because the map uses Leaflet's default SVG renderer.
    • Reading Leaflet 1.9.4 [A]:
      • _projectLatlngs is the same arithmetic as latLngToLayerPoint: getZoom() is _zoom, then crs.scale, _transform, _round, _subtract(pixelOrigin).
      • The clip shortcut uses exactly clipPolygon's bounds (renderer._bounds ± weight). When every point is inside, clipPolygon returns the same points in the same order. rings.slice() keeps _simplifyPoints from changing _rings.
      • The _bounds from the decoder equals Leaflet's extend over the same vertices.
  2. Sound optimisation: yes, apart from F1.
    • Caching: nothing new is cached. Rings are decoded again from the cached response on each draw, a metric or theme change only calls setStyle (the d attribute is unchanged, [T]), and zoom or pan go through Leaflet's normal _project/_update with _rawPxBounds and _rings set together.
    • No growth [T] (lifecycle.js, 8 layer switches kommune ↔ postnummer ↔ region ↔ landsdel):
      • map layers 102 / 608 / 8 / 14 and interactive targets 100 / 606 / 6 / 12, the same as master on every switch;
      • one group, 0 tooltips left on the map after leaving it, keys unique and equal to the row count;
      • JS heap after GC was steady and lower than master: 12–16 MB against 17–24 MB.
    • Filter and layer changes: no stale geometry on any of these steps.
    • Listeners: the group's tooltip handlers go with the group in remove()/destroy(); nothing is attached outside Leaflet.
    • Tooltip behaviour [T]:
      • Hover from Aarhus to Skanderborg (adjacent), then Favrskov, then Odense shows exactly one tooltip naming the shape under the pointer.
      • Leaving the map closes it.
      • Taps at 375×560 and 360×640 name the tapped area.
      • Master sometimes left two tooltips open (old per-shape behaviour); the PR shows exactly one, which is a side improvement.
    • Callers: no caller passes a stray second argument to decodeRings. Map, Live and Packets pass it as a callback with one argument.
  3. The perf test still measures the real path [A][T].
    • The step is unchanged: it reads AnalyticsDagiAreas.mapTiming() after a real tap. drawMs covers shape creation, the group, bindTooltip, addTo (project, clip, SVG) and fitBounds.

    • No work moved past the window: paintMs (first frame) drops by the same order as decode + draw.

    • A/B on this VM, 5 alternating rounds, same recipe (375×560, 4×, real tap):

      kommune work best / median postnummer work best / median postnummer first frame median
      master 1988 / 3000 ms 6587 / 7566 ms 8554 ms
      PR 1163 / 1851 ms 2740 / 3171 ms 4056 ms
      G = PR with group focus listeners kept 1487 / 1716 ms 3980 / 4826 ms 6180 ms
    • The ratio (postnummer about 2.4× faster) agrees with the PR's local "about 2×". The absolute CI numbers are [K] as claimed, not verified (F6).

  4. Nothing else changed [T].
    • Six files changed: the two public/ files and four test files.
    • No cmd/, internal/ or .github change, so cmd/server stays read-only and no map[string]interface{} was added (0 in the diff).
    • No hex colours added.
    • scripts/check-xss-sinks.sh --diff origin/master exits 0 (run in a local clone at head).
    • The fork guards in deploy.yml and release-fast-path.yml appear 9 and 1 times (master, head and merged).
    • No closing keywords in the commit or the PR body ("Relates to Analytics: area overview and comparison by DAGI area (kommune, landsdel, region, postnummer) — research first #1002").
    • Commit author: dborup <kontakt@meshview.dk>, one commit.
    • The merge onto 61d8e5e4 is clean. Newer master (b7db1738) only touches sites/meshview-info/, and the merge is still clean.

Tests and mutants

What Result
node test-frontend-helpers.js (merged) [T] 746 passed, 0 failed
node test-dagi-choropleth.js / test-issue-740-m3b-dagi-packets-map.js / test-analytics-dagi-areas-map.js (merged) [T] 35 / 28 / 17 passed
Red before: the PR's unit tests on master's code [T] test-dagi-choropleth.js 4 red, test-issue-740-m3b-dagi-packets-map.js 1 red (vertex factory)
sh test-all.sh (merged, in a git clone, nothing else running) [T] 398 passed, 10 failed. All 10 are wall-clock perf asserts in files this PR does not touch (live-heard-filter, live-scope-color, 724, 728, 941, 730, 1055 ×2, dagi-filter, 598). Run one by one, master fails the same files on this VM (dagi-filter flips between runs). Environmental; CI "JavaScript Unit Tests & Lint" is green [K].
node scripts/run-e2e-shard.js --validate [T] OK, 318 suites across three non-empty shards
M3 E2E (merged, CI-prepared fixture: freshen, seed SQL, corescope-migrate, seeds 2073 / 199 / 245 / 122), 3 runs [T] 9/10 each time; all functional steps green, including the new identity step (0 differ in 6 views) and the tooltip step. The perf step fails on this VM for master too (F6)
M1 / M2 / #740 M3b packets-map / M3b boundary / M3b packets-live / map-popover / M3c analytics / #1055 M2 Live DAGI E2E [T] 9/9, 5/6 (M2 perf step only, the same on master: 1938 ms), 12/12, 5/5, 48 checks, 5 + 1 skipped, 30/30, 14/14
Go suites Not run locally: the PR changes no Go, and the server binary built from the merged tree served every E2E. [K] Go Build & Test, Ingestor, Libraries & CLI, Server 1–3 are green

Own mutants (M3 E2E plus my harness):

Mutant PR's E2E My harness / other
A: projection at Math.round(zoom) killed only collaterally (desktop tooltip step); identity step 0 differ (F2) killed (fitted z6.5 at 1440 wide)
B: clip tolerance 3·w survives (F3) killed: 1 differ, Skagen edge
C: clip check on the max side only killed (identity, 12–318 differ) —
D: pxBounds from the first ring only (multipolygon islands) killed, narrowly: 3 differ in one view (København z13) —
E: no closing-vertex drop survives (inert: no such vertex in the data) —
F: aria-describedby on every shape killed (desktop tooltip step) —
G: Group focus listeners kept (the author's "speed only" mutant) survives behaviour differs: restores master's Tab order and focus ring (F1)

UI, real-user walk [T]

The walk was the same on master and the PR at 375×560 (touch, light and dark), 360×640 (touch) and 1440×900 (light and dark). Each run started cold on #/analytics. Then: a tap on the "Areas (DAGI)" tab, a tap on "Show map" (92×44 on a phone), a tap on Aarhus on the visible map, then a tap on Odense, then "Postnummer", then a tap on 8000, then "Hide map".

  • Every step worked by tap.
  • Each tap updated the URL (kommune=0751 → kommune=0461 → postnr=8000), opened the card, and named the area in the tooltip.
  • The map's top stayed fixed (94 px at 375×560).
  • No sideways scroll and no page errors.
  • Fresh-map screenshots are byte-identical between master and the PR. The only visual difference after a tap is the focus ring (F1).
  • Note: at 375×560, Playwright's scrollIntoViewIfNeeded parks "Show map" under the bottom menu, and a tap there hits the menu. This is the same on master. A real user scrolls the button above the menu, and at mid-screen it is reachable. It is not caused by this PR.

CI per job (head 1bceb036, run 46883900518) [K]

Green: Go Build & Test, Go Ingestor Tests, Go Libraries & CLI, Go Server Tests 1/3, 2/3 and 3/3, JavaScript Unit Tests & Lint, Script & Container Unit Checks, Playwright E2E 1/3, 2/3 and 3/3, Validate Docker Image, Verify Go Test Assignments, Verify E2E Shards & Coverage, Build & Publish Docker Image.

Skipped (as usual on a PR): Publish Badges & Summary, Release Artifacts, Deploy Staging.

Not verified

  • Firefox and WebKit/Safari focus behaviour of SVG paths with focus listeners. F1 was measured in Chromium only, and on iOS Safari the impact may differ.
  • A real iPhone.
  • The CI timing numbers in the PR (82.4 / 145.5 ms), because the logs need a login.
  • Absolute perf against the 250 ms budget on this VM (F6).
  • compression.gzip byte sizes (DAGI_GZIP_BASE_URL was not set).
  • Head checked with git ls-remote before and after: unchanged at 1bceb036.

…e identity gaps (#1002 M3)

Review of #1091 (F1-F4):
- F1: Group and Shape no longer override _addFocusListeners. Chromium makes
  an SVG path focusable once it has focus listeners, so the no-op took all
  99 (605) shapes out of the Tab order and gave a tapped shape no focus
  ring. Master's behaviour is back; an E2E step pins it (Tab from "Hide
  map": the map, then the first three shapes, each described by the
  tooltip; a clicked shape takes the focus).
- F2: the identity step now draws fractional zooms (9.25, 11.75), so a
  projection at a rounded zoom no longer passes.
- F3: the identity step pans Skagen (9493) at z8.5 so each side crosses the
  clip box edge by -3..+3 px, so a wider clip tolerance no longer passes.
- F4: the closing-vertex branch in Shape._setLatLngs is gone (the decoder's
  rings never repeat their first vertex).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@adminopenclaw8-sketch

Copy link
Copy Markdown
Collaborator Author

Fix round — CS-Macmini PR#1091

Review feedback addressed (commit af0da253)

  1. F1 (blocking): option (a). The _addFocusListeners no-ops on Group and Shape are deleted, so the shapes are back in the Tab order and a tapped shape keeps its focus ring. The code comment and PR text no longer claim they are unfocusable. New E2E step: Tab from "Hide map" goes to the map, then the first three shapes (0101, 0147, …), each with aria-describedby and the tooltip open; a clicked shape takes the focus. Putting the no-op back turns this step red.
  2. F2: the identity step now includes Aarhus z9.25 and Fanø z11.75 (both views and both layers). Mutant A (Math.round zoom) now fails with 11/2/63/3 paths differing.
  3. F3: the identity step sweeps Skagen (9493) at z8.5, panning so each of its four sides crosses the clip box edge by -3 to +3 px, and asserts that some cases fall between 1× and 3× the stroke weight. Mutant B (3 * w) now fails with 5 paths differing (9440).
  4. F4: the closing-vertex branch is removed (the decoder leaves it implicit; 0 of 3,095 rings repeat it), the dead Shape no-op is deleted with F1, and the unused LatLng.equals in tests/fake-leaflet.js is gone.
  5. F5: with F1 option (a), aria-describedby goes on each focused shape and on the hovered one, as on master. The one shared tooltip id is stale after close in both versions.
  6. F6: noted in the PR. Absolute budgets were not checkable on the review VM; only A/B.

Perf, re-measured (local, plain 4× CPU throttle, 375×560, best of 3, same machine and run):

master previous head this head
kommune 55.3 ms 30.9 ms 32.2 ms
postnummer 108.8 ms 56.1 ms 59.3 ms

Still about 1.8× faster than master. The PR table is updated.

Tests: M3 E2E 10/10 (new Tab step and 11 identity views, 0 differ). test-dagi-choropleth.js 35, test-issue-740-m3b-dagi-packets-map.js 28, test-analytics-dagi-areas-map.js 17 and test-frontend-helpers.js 746 all pass. CI on af0da253: all jobs green (Go ×6, JS, Script, Playwright 1/3, 2/3, 3/3, Docker, Go Test Assignments, E2E Shards).

Not verified: Firefox and WebKit focus behaviour.

@dborup

dborup commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Review — CS-Minimax PR#1091 — head af0da25

Dom: APPROVE med nits

This is a delta re-review after "Review — CS-VM1 PR#1091" (REQUEST CHANGES) and "Fix round — CS-Macmini PR#1091". All six points are closed:

  • F1: the blocking finding. The shapes are back in the Tab order. Focusing a shape opens its tooltip and sets aria-describedby, and a tapped shape gets its focus ring, all as on master.
  • F2 and F3: both reviewer mutants now die in the PR's own identity step.
  • Paths: my own master-vs-PR harness on the real Analytics map gives 126 views and 36,522 path records, with 0 differ.

Two nits are left; neither blocks.

Evidence tags: [T] tested here (macOS arm64, Playwright Chromium, merged tree b49e02fd = origin/master b7db1738 + head, Go 1.26). [A] reading or reasoning. [K] CI on GitHub.

Findings

# Severity Finding Evidence
N1 Nit (test gap) Nothing pins that a shape keeps the decoder's bounds in _bounds. My mutant N3, L.latLngBounds(b[0], b[0]) (a degenerate box), survives the unit tests, the M3 E2E (10/10) and my path harness (0 differ). Today it has no effect, because nothing reads a shape's bounds: the map is fitted from the choropleth's own s/w/n/e, and Leaflet only calls _bounds.isValid() in _project. The unit test "each shape keeps the decoder's LatLngs and bounds" checks the constructor argument in tests/fake-leaflet.js, not Shape._bounds. Optional fix: an assertion in the identity step that fast.getBounds() equals ref.getBounds(). [T] mutant N3; [A] dagi-choropleth.js:166, :299
N2 Nit (test strength) The new Tab step's tooltip check compares the tooltip with itself. It asserts that the element named by aria-describedby contains the text of the open tooltip's <strong>. It does not check that this text names the focused shape (tabbed[3].key). By hand, the tooltip does name the focused shape: 0101 → København, 0147 → Frederiksberg, 0151 → Ballerup, and so on. A focus listener that opened the wrong shape's tooltip would be caught today only indirectly, by the described check. Optional: compare it with the row name for the focused key. [T] walk below; [A] test-issue-1002-m3-dagi-choropleth-e2e.js:251-253
I1 Info (side improvement) On Tab, master leaves up to 4 tooltips open at once, because each shape has its own tooltip and the previous one has not closed yet. This PR shows exactly one. This is also why the PR's Tab step fails on master: it reads the first open tooltip, which is Odense, the one left from the tap. [T] walk, PR E2E against master
I2 Info (not this PR) On a cold phone start, the "Tip: swipe in from the left edge" toast covers the top of the map at 375×560. Taps below it work. Master and the PR give byte-identical screenshots here. [T] screenshots

Answers to the points

F1: Tab order, focus tooltip, focus ring. Closed [T].

  • Both _addFocusListeners no-ops are gone (Group and Shape), and the code comment now gives the correct reason.
  • My walk at 375×560 and 360×640 (touch) uses master and the merged tree side by side. Tab from "Show/Hide map" goes map canvas → 0101 → 0147 → 0151 → 0153 → 0155, identical on both.
  • Each focused shape gets an aria-describedby whose element names that shape.
  • After a tap on Aarhus and then Odense, document.activeElement is the tapped path with outline: auto (focus ring). The screenshots after the tap are byte-identical to master (5 of 5 pairs).
  • My mutant N2 puts the Group._addFocusListeners no-op back, and it is killed by the new Tab step: Tab from "Hide map" did not go map, then the first three shapes.

F2: fractional zoom. Closed [T].

  • The identity step now covers Aarhus z9.25 and Fanø z11.75.
  • The reviewer's mutant A (crs.scale(Math.round(m.getZoom()))) now fails the identity step with 11 paths differing (kommune Aarhus z9.25). The desktop step fails as well.
  • My harness gives 7,410 differing records for mutant A.

F3: clip tolerance boundary. Closed [T].

  • The Skagen (9493) z8.5 sweep runs 28 cases, of which 8 fall between 1× and 3× the stroke weight.
  • The reviewer's mutant B (3 * w) now fails the identity step with 5 paths differing (9440). My harness gives 12 differing records for mutant B.

F4. Closed [T][A].

  • The closing-vertex branch is gone, and this._latlngs = rings. This is safe because decodeRings leaves the closing vertex implicit; an existing unit test pins that.
  • The dead Shape no-op is gone, and so is LatLng.equals in the fake.

F5. Closed [A][T].

  • aria-describedby goes on the focused or hovered shape only, through Group._setAriaDescribedByOnLayer, which is gated on _tooltip._source.
  • The desktop step still asserts exactly 0461,0751 after hovering.

F6. Noted [K].

  • CI on this head measured kommune 99.1 ms and postnummer 177.6 ms against the 250 ms budget (Playwright E2E 2/3 job log). That leaves about 29% headroom on postnummer, against the 309.6 / 322.1 ms red runs on master.

Paths byte-identical to master: confirmed [T].

  • My own cmp-paths.js runs two servers side by side: the same Go binary and the same prepared fixture, one with public/ from origin/master and one with public/ from the merged tree.
  • It loads the real #/analytics?tab=dagi-areas&layer=…&map=1 (tiles blocked), hooks L.Map to reach the app's map, and compares every path.dagi-choro-shape, in DOM order, on class, d, fill, stroke, fill-opacity, stroke-opacity, stroke-width, fill-rule, stroke-linecap and stroke-linejoin.
  • Configurations:
    • kommune and postnummer at 375×560 and 1440×900;
    • postnummer dark;
    • region and landsdel at 375×560.
  • 18 views each:
    • fitted (z6 / z6.5, the same on both);
    • Aarhus z9.25 and z11, København z13 and z15.5, Fanø z11.75, Bornholm z9.25, Christiansø z13, Læsø z11, Ærø z11.5, Skagen z8.5, Odense z7.75;
    • five panBy steps without reprojection (150/80, −37/13, 1/−1, 200/−150, −3/3);
    • an animated zoom-in through the zoom control.
  • Result: 126 views, 36,522 records, 0 differ.
  • The harness is sensitive: mutants A, B and N1 give 7,410, 12 and 245 differing records.

Perf numbers updated [T][K].

  • The PR table and the fix-round table are updated.

  • My local A/B at 375×560 and a plain 4× throttle, 3 alternating rounds, best decode + draw per round:

    kommune postnummer
    master 68.6 / 69.8 / 69.8 ms 134.5 / 137.2 / 137.6 ms
    PR 39.4 / 40.5 / 41.8 ms 81.3 / 81.3 / 81.9 ms
  • That is about 1.7× faster, which matches the PR's ~1.8×. Decode is about 1–2 ms slower, because building the LatLngs moved into it; draw is about halved.

  • My absolute numbers are higher than the author's, but the ratio agrees.

No behaviour change beyond the purpose [T][A].

  • The only user-visible difference I found is I1, one tooltip instead of several, which is an improvement.
  • The six changed files are public/dagi-choropleth.js, public/dagi-filter.js and four test files. The decodeRings default output is unchanged, and the extra argument is optional.
  • No cmd/, internal/ or .github/ change, so cmd/server stays read-only. 0 added map[string]interface{}. No hex colours in the public/ diff.
  • scripts/check-xss-sinks.sh --diff b7db1738 exits 0, run in a clone of the merged tree.
  • Fork guards: the repository guards appear 9 times in deploy.yml and once in release-fast-path.yml; .github/ is identical to master.
  • No closing keywords in the 2 commits or the PR body ("Relates to Analytics: area overview and comparison by DAGI area (kommune, landsdel, region, postnummer) — research first #1002").
  • Both commits have author and committer dborup <kontakt@meshview.dk>.

Tests and mutants

What Result
go test ./... in cmd/server and cmd/ingestor (merged) [T] both ok (the PR changes no Go)
sh test-all.sh (merged) [T] 406 passed, 2 failed. Both failures need a git repository: test-issue-628-vendor-gitattributes.js and test-issue-715-og-denmark.js run git check-attr / git ls-files, and the git archive export has no repository. Rerun in a git clone of the merged tree: 4/4 and 10/10. So, in effect, 408 passed.
node test-frontend-helpers.js (merged) [T] exit 0
test-dagi-choropleth.js / test-issue-740-m3b-dagi-packets-map.js / test-analytics-dagi-areas-map.js (merged) [T] all pass
Red before: the PR's unit tests on master's public/ [T] test-dagi-choropleth.js 4 failed (the decoder's LatLngs, the group tooltip ×2, the shape bounds); test-issue-740-m3b-dagi-packets-map.js 1 failed (the vertex factory)
Red before: the PR's M3 E2E against a master server [T] 8 passed, 2 failed: the identity step (shapeClasses is not a function) and the Tab/tooltip step (I1)
PR's M3 E2E (merged), CI-prepared fixture: freshen, Kpa-clawbot#1486 seed SQL, corescope-migrate, seeds 2073 / 199 / 245 / 122 [T] 10/10, four times (one baseline and three A/B rounds). The identity step gives 0 differ in 11 views. Perf: 79.7–81.9 ms postnummer.
M1 / M2 / #740 M3a / M3b boundary / M3b packets-map / M3b packets-live / M3c / M3 customizer [T] 9/9, 6/6, 11/11, 5/5, 12/12, 48 checks, 30/30, 7/7
#1055 M2 Live DAGI (its own server, E2E_PORT_BASE=13710) [T] 14/14
node scripts/run-e2e-shard.js --validate [T] OK, 318 suites across three shards

Mutants. I ran each one against the PR's E2E and against my harness, with one server per mutant:

Mutant PR's E2E My harness
A (reviewer): projection at Math.round(zoom) killed: identity step (11 differ, Aarhus z9.25) and desktop step killed, 7,410 differ
B (reviewer): clip tolerance 3 * w killed: identity step, Skagen sweep (5 differ, 9440) killed, 12 differ
N1 (mine): this._parts = this._rings (no slice(), so _simplifyPoints changes _rings and a later pan clips simplified rings) killed: Skagen sweep, 66 differ killed, 245 differ (pans)
N2 (mine): Group._addFocusListeners: function () {} put back (the F1 regression) killed: Tab step n/a (paths unchanged)
N3 (mine): degenerate shape _bounds survives (N1 nit) survives, 0 differ: inert in the app today

UI: real-user walk [T]

The walk ran master and the PR side by side at 375×560 and 360×640, with touch, starting cold on #/analytics:

  1. Tap the "Areas (DAGI)" tab.
  2. Scroll "Show map" (93×44) to mid-screen, check that it is hit-testable, and tap it.
  3. Tap Aarhus on the visible map, then tap Odense. Each tap updates the URL (kommune=0751 → kommune=0461), opens the card, shows one tooltip naming the area, and leaves the focus ring on it. The map stays in place.
  4. Tab through the map (see F1).
  5. Tap the "Postnummer" button (106×44), then a tap on the map picks the area (postnr=8000 at 375, postnr=8240 at 360; the same on master).
  6. Tap "Hide map". The map is hidden and map=1 leaves the URL.

No step was impossible, and nothing had to be closed first. There was no sideways scroll and there were 0 page errors on either side. The screenshots match master byte for byte.

CI per job (head af0da253, run 46927279661) [K]

Not verified

  • Firefox and WebKit/Safari focus behaviour of the SVG paths, and a real iPhone. All of this review ran in Chromium.
  • CI absolute numbers beyond the one job log quoted above.
  • compression.gzip byte sizes (DAGI_GZIP_BASE_URL was not set).
  • go test -race, and Go 1.27.1 (CI's version). The PR changes no Go.
  • The PR is still a draft. This review covers the code; it does not mean the PR is ready.
  • I checked the head with git ls-remote before and after: it was unchanged at af0da253.

@dborup
dborup marked this pull request as ready for review December 2, 2026 20:52
@dborup
dborup merged commit 644576a into master Dec 2, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants