Optimize weighted clustering using Supercluster v9 storage and allocation techniques
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 15/100
- Tipo de issue
- Refactorización
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 143
- Forks
- 24
- Merge medio
- 1 d 4 h
- PR fusionados (30 d)
- 18
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de visgl/flowmap.gl
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
visgl/flowmap.gl#125 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
visgl/flowmap.gl#116 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
visgl/flowmap.gl#60 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
visgl/flowmap.gl#59 ·
Los mantenedores suelen responder en 1 día
-
Using flowmap.gl in ObservableAbierto
Dificultad 3/5 1-2 días Aptitud para principiantes 25/100
visgl/flowmap.gl#41 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de visgl/flowmap.gl
Issues similares
-
accessibility area:ci ci-test level:low priority:high type:test
Dificultad 2/5 1-3 horas Aptitud para principiantes 71/100
skytuhua-org/Gen-V1#3132 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
drmrd/vernacular#1238 ·
Los mantenedores suelen responder en 1 día
-
question
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
-
enhancement migration-prioritized
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Hudson-Pufferfish/local-party-console#136 ·
Los mantenedores suelen responder en 1 día
-
priority:medium
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día