Optimize weighted clustering using Supercluster v9 storage and allocation techniques

オープン
#126 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
15/100
issue の種類
リファクタリング
明瞭さ
おおむね明確
活発さ
活発
技術スタック
typescript

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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/reduce aggregate properties but do not affect centers or subsequent merges. Our weights are normally max(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. Our ClusterIndex stores 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.ts
  • packages/data/src/cluster/globe-projection.ts
  • packages/data/src/cluster/ClusterIndex.ts
  • packages/data/src/FlowmapSelectors.ts
  • test/node/clustering.test.js
  • test/node/flat-clusters.json

Proposed approach

  1. 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.
  2. 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.
  3. Reduce temporary allocations in neighbor queries and level construction.

    • Evaluate KDBush 4.1.0's withinInto with 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.
  4. 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

Both weighted-points proposals remained open at review time. Adopting unmodified Supercluster is therefore not the proposed implementation.

主要言語
TypeScript
スター
143
フォーク
24
平均マージ
1日 4時間
マージ済み PR(30日)
18

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

visgl/flowmap.gl のほかの issue

visgl/flowmap.gl の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。