Optimize weighted clustering using Supercluster v9 storage and allocation techniques
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 15/100
- Tipo di issue
- Refactoring
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- data-visualization, performance
Direzione di ricerca
Start in packages/data/src/cluster/cluster.ts, globe-projection.ts and ClusterIndex.ts, and read test/node/clustering.test.js with the flat-clusters.json fixture. The first step is a measured baseline of clusterLocations and buildIndex, not a code change. Done means the fixture and globe tests still pass, weights affect merges at every zoom, and before/after timings and memory are reported.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem
Our location-clustering implementation is based on an older Supercluster implementation and still allocates objects for individual points and clusters. Modern Supercluster offers useful memory and allocation optimizations, but replacing our implementation directly would change weighted clustering and globe behavior.
Optimize our implementation by adapting the relevant Supercluster v9 techniques while preserving the existing clustering semantics and public hierarchy format.
Findings from the compatibility review
Reviewed Supercluster 9.1.0 and the local flowmap.gl checkout at 758f7605efe20cf5ec764345593a93460b11ec5b.
- Custom weights still do not affect Supercluster geometry. Its centers are weighted by original point counts.
map/reduceaggregate properties but do not affect centers or subsequent merges. Our weights are normallymax(abs(total incoming), abs(total outgoing)), with zero weights treated as 1 during clustering. - Post-processing centers is insufficient. Moving a center changes which locations merge at subsequent zoom levels, so weighting must participate in hierarchy construction.
- Globe clustering requires separate geometry. Our current checkout supports spherical neighbor distances and weighted spherical centers, including dateline and polar neighbors. Supercluster uses Mercator coordinates and exposes no projection hook.
- The hierarchy contracts differ. We emit
ClusterLevel[], compact unchanged levels, handle duplicate-coordinate levels specially, and use level-specific cluster nodes. Supercluster carries cluster IDs across zooms. OurClusterIndexstores nodes by ID and uses each node's zoom, so directly adapting those IDs would require care. - The spatial index already uses typed arrays. The lockfile resolves KDBush 4.1.0, and the Mercator path constructs it with
Float32Array. The opportunity is chiefly internal point/cluster storage and temporary allocations, rather than merely upgrading KDBush.
Relevant local source:
packages/data/src/cluster/cluster.tspackages/data/src/cluster/globe-projection.tspackages/data/src/cluster/ClusterIndex.tspackages/data/src/FlowmapSelectors.tstest/node/clustering.test.jstest/node/flat-clusters.json
Proposed approach
-
Establish an end-to-end baseline.
- Measure
clusterLocations,buildIndex, and their combined cost separately. - Include representative flow datasets and seeded synthetic distributions: dense clusters, sparse/global points, duplicate coordinates, highly unequal weights, and globe dateline/polar cases.
- Record warm-up, repeated-run timings, dataset sizes, runtime versions, and memory measurements. Include typed-array/ArrayBuffer memory rather than relying only on JS heap.
- Measure hierarchy materialization too: our consumers require the full hierarchy, unlike a benchmark that only builds an upstream index.
- Measure
-
Replace internal point/cluster objects with compact numeric storage.
- Evaluate flat typed arrays or separate typed arrays for coordinates, weights, point counts, processed zooms, IDs, and parent IDs.
- Keep original locations and external string/number IDs outside numeric buffers.
- Keep weight separate from point count; retain fractional/large weights without integer truncation or overflow.
- Preserve sufficient coordinate precision and the globe's third coordinate. Do not mechanically copy Supercluster's Int32 coordinate encoding: changed rounding can affect neighbor boundaries, centers, and hierarchy membership.
- Materialize the existing public
ClusterLevel[]objects at the boundary.
-
Reduce temporary allocations in neighbor queries and level construction.
- Evaluate KDBush 4.1.0's
withinIntowith reusable neighbor buffers on the Mercator path. - Reuse scratch buffers where ownership permits; do not overwrite arrays retained by earlier hierarchy levels or indexes.
- Preserve existing unchanged-level compaction and duplicate-location handling.
- Profile the globe spatial hash separately and apply relevant buffer reuse there without replacing spherical geometry with Mercator.
- Evaluate KDBush 4.1.0's
-
Land focused, measured changes.
- Prefer a benchmark/compatibility baseline followed by independently reviewable optimizations.
- Compare results after each step and retain changes justified by measured improvements.
- Preserve upstream license notices for adapted code.
Behavior to preserve / acceptance criteria
- Custom weights affect centers and subsequent merges at every zoom; point count remains distinct from weight.
- Preserve the current zero-weight fallback and flow-derived weight calculation.
- Existing flat hierarchy fixture remains unchanged, including IDs, centers, zoom levels, children, and duplicate-coordinate behavior. Any intentional precision change requires explicit review.
- Globe tests preserve dateline/polar neighbor behavior, finite centers, and descendants through independent merges.
- Every retained level preserves all leaves exactly once.
- Flow aggregation preserves total magnitude and correct origin/destination grouping.
- Public
ClusterLevel[], custom ID/name callbacks, supplied hierarchies, manual clustering levels, selections, and selector caching continue to work. - Report before/after construction time and memory for representative Mercator and globe workloads, including hierarchy output and
buildIndex. - Run the relevant regression suite; document any tradeoffs or regressions.
Focused comparisons already performed
Using the current local algorithm and Supercluster 9.1.0 source with KDBush 4.1.0:
| Case | Current implementation | Supercluster 9.1.0 |
|---|---|---|
Equatorial points at longitude 0° and 10°, weights 1 and 9, maxZoom: 0 |
Center at 9° | Center at approximately 5°, even with weight aggregation |
Add an equatorial point at 35° with weight 1; maxZoom: 1, default radius/extent |
One cluster at zoom 0 | Two nodes at zoom 0 |
Points at 179° and −179°, latitude 10°, weights 1 and 3, maxZoom: 5 |
Globe mode merges the pair | Pair remains separate at zoom 0 |
The existing serialized flat-hierarchy fixture also passed in the standalone comparison. These were focused checks, not a full test-suite run or an end-to-end performance benchmark.
Upstream references
- Supercluster 9.1.0 implementation
- Supercluster v9 performance release: upstream reports 23% faster indexing, 94% less transient allocation, 57% lower peak heap, and 65% less retained memory on a sample of one million points. These are upstream benchmark results, not measured improvements over flowmap.gl.
- Original weighted-points proposal #119
- Later adaptation #236
Both weighted-points proposals remained open at review time. Adopting unmodified Supercluster is therefore not the proposed implementation.
- Lingua principale
- TypeScript
- Stelle
- 143
- Fork
- 24
- Merge medio
- 1g 4h
- PR unite (30g)
- 18
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di visgl/flowmap.gl
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
visgl/flowmap.gl#125 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
visgl/flowmap.gl#116 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
visgl/flowmap.gl#60 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
visgl/flowmap.gl#59 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
visgl/flowmap.gl#41 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di visgl/flowmap.gl
Issue simili
-
accessibility area:ci ci-test level:low priority:high type:test
Difficoltà 2/5 1-3 ore Idoneità per principianti 71/100
skytuhua-org/Gen-V1#3132 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
drmrd/vernacular#1238 ·
I maintainer di solito rispondono entro 1 giorno
-
question
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
enhancement migration-prioritized
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
Hudson-Pufferfish/local-party-console#136 ·
I maintainer di solito rispondono entro 1 giorno
-
priority:medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno