# JunctionTools preview latency audit — 2026-09-14 Investigation only; implementation unchanged. Baseline commit 6a8f026. Real source/config: workbench-data/import-fE8XI7, four-node cluster, radius 21m. Called exported editPreview with selection={cluster:actualClusterId}, no added constraints; this measures repeated preview processing, not actual browser input-to-paint latency. No writes to user workspace data. Performance wrappers in /private/tmp/profile-junction-preview.js instrument exported model/solver/compiler/projection stages before server import. ## Measurements CPU-profiled run: 1 cold + 5 repeated calls. Then independent unprofiled process: 1 cold + 2 repeated calls. Unprofiled repeated values: | Phase | Run 1 ms | Run 2 ms | | --- | ---: | ---: | | OSM/model build | 66.8 | 73.7 | | Constraint resolution + handle construction | 306.3 | 313.1 | | Whole-area geometry | 1996.8 | 1951.3 | | Selected junction projection | 0.83 | 0.56 | | Total editPreview | 2375.9 | 2344.7 | | JSON.stringify response | 175.8 | 167.1 | Response: 24,185,780 UTF-8 bytes. Counts include 20,942 lane-separator features (13.59MB), 4,978 direction-arrow features (4.24MB), 860 connectors (3.28MB), 2,212 center-line features (1.88MB). These are whole-region collections, not just the selected cluster. This already costs about 2.5 seconds before network/browser parsing/rendering. Small sample; do not label this P95. CPU sampling across six selected-cluster previews: compileLaneMarkings inclusive ~7.1s, trimLineBeforeFirstControl inclusive ~6.8s (nested, do not sum); compileConnectors ~2.4s; resolver ~1.5s. The biggest hotspot is control avoidance, not core filling or four-island geometry. trimLineBeforeFirstControl probes every 0.25m and ringsOverlapControl scans control features; controlBounds alone consumes ~2.35s self time across six calls. Road/junction affects construction repeatedly scans global connections. Arrow assets are synchronously reread via loadManifest during generation. ## Confirmed causes 1. compileEditCandidate rereads/parses OSM and rebuilds the model, resolves constraints and compiles all area geometry for every request. selection reaches handle filtering; it does not restrict geometry compilation. 2. resolveDirectEditConstraints constructs all road/junction/cluster/lane handles before selectHandles filters them. Cluster selection does not avoid global handle/affects construction. 3. editPreview returns full-area layers. localJunctionPreview filters them only after browser receipt. Server JSON response is not compressed by sendJson; stringify is synchronous. 4. UI schedules live changes with 80ms trailing debounce; settle flushes immediately. AbortController abandons requests on the client, but synchronous server computation has no cancellation signal or cooperative yields, so obsolete work can still occupy the single event loop. 5. EditPreviewLayer.show clears touched sources, reparses GeoJSON, recreates features and reprojects to EPSG:3857. JunctionTools does scope its displayed collections, so do not claim it necessarily draws all ~30,000 features. Browser parsing/filtering/paint duration has not been measured. 6. degraded only labels compute >300ms. It neither stops computation nor includes response serialization/network/paint. Historical comments about ~142ms reflect different data/code and are not current performance evidence. Priority implied by evidence: avoid whole-area marking/control recomputation; generate selected handles before filtering; return scoped layers; cache stable parsing/assets. Do not promise 300ms from debounce tweaks, worker offloading alone, or merely adding Maps. Backend computation alone must be reduced by roughly an order of magnitude.