fix(Sankey): avoid exponential depth traversal on dense graphs#7479
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Walkthrough
ChangesSankey depth recursion guard and layout tests
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/chart/Sankey.spec.tsx`:
- Around line 860-866: In the test "renders a heavily branching graph without
freezing the main thread", add a call to advance pending timers (such as
jest.runAllTimers() or the appropriate timer advancement utility from the test
setup) immediately after the render call for the Sankey component and before the
expect assertions. This ensures all pending timers are flushed to prevent test
flakiness according to the project's coding guidelines.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3ac562be-f752-4725-a557-9976b3c7b747
📒 Files selected for processing (2)
src/chart/Sankey.tsxtest/chart/Sankey.spec.tsx
Bundle ReportChanges will increase total bundle size by 1.43kB (0.03%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: recharts/bundle-umdAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-sankeyAssets Changed:
view changes for bundle: recharts/bundle-es6Assets Changed:
view changes for bundle: recharts/bundle-cjsAssets Changed:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7479 +/- ##
==========================================
+ Coverage 88.14% 88.15% +0.01%
==========================================
Files 608 609 +1
Lines 14211 14229 +18
Branches 3567 3569 +2
==========================================
+ Hits 12526 12544 +18
Misses 1495 1495
Partials 190 190 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@ckifer @PavelVanecek would appreciate a review when you have a moment - this fixes a freeze on dense branching graphs (#7478). |
|
@dm-gthb may I ask you to resolve the merge conflicts please? (Sorry if this is posted multiple times, GitHub is showing me errors when I send) |
|
@PavelVanecek done, resolved the conflicts and merged latest main |
Description
Fix Sankey layout freezing on dense, heavily branching graphs by pruning depth assignment in
updateDepthOfTargets.When computing node
depth(longest path from a source), the layout recurses into every target even when depth does not grow. On graphs where many paths share nodes, that re-walks every distinct path combinatorially. The freeze is not limited to very large datasets — it can happen with modest node/link counts when the graph branches heavily.The fix only recurses when
curNode.depth + 1exceeds the target's current depth. Once depth stops increasing, the subtree is already correct.Also exports
computeDatafromSankey.tsxfor unit tests (same pattern as Treemap'scomputeNode). It is not added tosrc/index.ts, so the public API is unchanged. New test coverage is described below.Related Issue
#7478
Motivation and Context
Sankey layout can freeze the browser when depth assignment must follow the longest path to each node. Without pruning, the layout walks every distinct path combinatorially.
Starting from relatively small graphs, this is already a problem — not only at “big data” scale. For example, the issue reproducer uses only 85 nodes and 112 links (
makeBranchingChainData(28)).The cost is driven by path count (how many distinct routes exist through shared nodes), not by raw node/link totals alone. Modest node/link counts can still hang when the graph branches heavily.
The fix is a small guard in
updateDepthOfTargets. Existing Sankey tests that pin exact coordinates still pass, so layout geometry for typical graphs is unchanged.How Has This Been Tested?
Added unit tests in test/chart/Sankey.spec.tsx covering the Sankey layout for large, heavily branching graphs:
Screenshots (if appropriate):
N/A — performance fix with no visual change for existing graphs.
Types of changes
Checklist:
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests