chart: Avoid quadratic Sankey topology computation (#2682)
# Title chart: Avoid quadratic Sankey topology computation # Body Closes #2681 ## Description `Sankey::topology` previously computed node ranks in repeated waves. Each wave allocated an `N`-element boolean vector and scanned all node indices to build the next frontier. A valid chain of `N` nodes therefore required `O(N^2)` work for both the forward and backward rank passes, blocking the UI while the chart was painted. This change replaces that loop with a degree-based topological traversal. Each node and link is processed once per direction, reducing rank computation to `O(V + E)` while preserving the existing longest-path `depth` and `height` values and circular-link detection. The public API and chart rendering flow are unchanged. ## Screenshot | Before | After | | ------ | ----- | | <img width="1972" height="1262" alt="sankey-pre-fix-reproduction" src="https://github.com/user-attachments/assets/3b97270e-b056-429e-831e-8beadc935842" /> | <img width="1972" height="1262" alt="sankey-post-fix-verification" src="https://github.com/user-attachments/assets/0c88a56a-3c47-45bf-b248-c921ce0d8a6e" /> | With the same optimized PoC against the checked-in `sankey.rs`: - Before: a valid 50,000-node chain exceeded the 5-second timeout (`exit_code=124`). - After: the same chain completed in 5 ms (`exit_code=0`); a same-size shallow star completed in 4 ms. ## How to Test ```sh cargo test --locked --offline --all cargo clippy -p gpui-component --lib -- --deny warnings cargo run -p gpui-component-story -- Chart ``` The automated test suite includes a 50,000-node chain regression case for `Sankey::topology`. For the manual story check, open the Chart story and scroll to the `Sankey Chart - TSLA` examples. ## AI Assistance AI assisted with the implementation, regression test, and PR draft. The contributor reviewed the generated changes and test evidence before submission. ## Checklist - [x] I have read the [CONTRIBUTING](../CONTRIBUTING.md) document and followed the guidelines. - [X] Reviewed the changes in this PR and confirmed AI generated code (if any) is accurate. - [x] Passed `cargo run` for story tests related to the changes. - [x] Not platform-specific; no platform-specific rendering path was changed. --------- Co-authored-by: Floyd Wang <gassnake999@gmail.com>
L
luren committed
f2f0f563292114fecf55fb8ab92a97e14989dbd0
Parent: 6e3f241
Committed by GitHub <noreply@github.com>
on 8/12/2026, 3:51:15 AM