Repository navigation
perf(analytics): DAGI choropleth draws in half the time, same paths (#1002 M3) - #1091
Conversation
#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>
Rapport — CS-Macmini PR#1091 #1002 M3 perf — head 1bceb03Status: 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 Evidence tags: [T] test or command run locally, [A] reasoning or assumption, [K] CI on GitHub. 1. Regression or always close? Measured times
2. Profile (4×, 375×560, postnummer: 605 shapes, 2,183 rings, 44,487 vertices)
3. Changes and their measured effect (local, 4×, postnummer work)
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
Rules
Local runs
Open points for the owner
|
Review — CS-VM1 PR#1091 — head 1bceb03Dom: 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 Findings
F1: what to do (either option closes it)
Answers to the questions
Tests and mutants
Own mutants (M3 E2E plus my harness):
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
CI per job (head
|
…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>
Fix round — CS-Macmini PR#1091Review feedback addressed (commit
Perf, re-measured (local, plain 4× CPU throttle, 375×560, best of 3, same machine and run):
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). Not verified: Firefox and WebKit focus behaviour. |
Review — CS-Minimax PR#1091 — head af0da25Dom: 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:
Two nits are left; neither blocks. Evidence tags: [T] tested here (macOS arm64, Playwright Chromium, merged tree Findings
Answers to the pointsF1: Tab order, focus tooltip, focus ring. Closed [T].
F2: fractional zoom. Closed [T].
F3: clip tolerance boundary. Closed [T].
F4. Closed [T][A].
F5. Closed [A][T].
F6. Noted [K].
Paths byte-identical to master: confirmed [T].
Perf numbers updated [T][K].
No behaviour change beyond the purpose [T][A].
Tests and mutants
Mutants. I ran each one against the PR's E2E and against my harness, with one server per mutant:
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
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
|
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:
6fcba31c51241991f5f14f71a7612474ebfa4ff54163cf54(head)a7612474ebfa4ff5The 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.PolygonandL.FeatureGroup(shapeClasses(L)indagi-choropleth.js). They draw the same paths:DagiFilter.decodeRings(resp, vertex): an optional vertex factory, so the decoder makes Leaflet's ownLatLngs. 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.latLngToLayerPoint(project, transform at the zoom's scale, round, subtract the pixel origin). It just skips the per-vertex scale and origin lookups.aria-describedbygoes 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:
Tests
L.polygonand the choropleth'sShapeon one map, then compares every path'sdattribute. It checks the fitted view, Aarhus at z11, København at z13, fractional zooms Aarhus z9.25 and Fanø z11.75 (zoomSnap0.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.aria-describedbyand the tooltip open; a clicked shape takes the focus.aria-describedby.decodeRings(resp, vertex)gives the same numbers, order and bounds as the default. Shapes keep the decoder'sLatLngs 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.jsgainedLatLng,Polygon.extendandFeatureGroup.extend.aria-describedbyon 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
LatLngper vertex instead of an array plus aLatLng, and no clip arrays for shapes that are inside. The number of DOM elements is unchanged.🤖 Generated with Claude Code