Skip to content

Fix O(n)^2 bar draw from per-bar getZeroBarDir - #8171

Open
short-int-ali wants to merge 3 commits into
plotly:mainfrom
short-int-ali:cursor/bar-zero-bar-dir-once-da7b
Open

short-int-ali wants to merge 3 commits into
plotly:mainfrom
short-int-ali:cursor/bar-zero-bar-dir-once-da7b

Conversation

@short-int-ali

Copy link
Copy Markdown

Compute getZeroBarDir once per bar trace instead of once per bar.

Closes https://github.com//issues/8157 once this change lands on plotly/plotly.js (this PR is on the fork; the agent token cannot open a cross-repo PR against upstream).

Same-sign traces scanned all calcdata for every bar. That made draw time quadratic. The cached value keeps the same outside-label side for zero-extent bars (#7872).

Tests

  • Jasmine file: test/jasmine/tests/bar_test.js
  • Focus: should keep zero-value outside labels on the same side as negative bars
  • Command: xvfb-run --auto-servernum --server-args="-screen 0 1280x1024x24" npm run test-jasmine -- bar --nowatch --report-spec
  • Result: Chrome 157.0.0.0 (Linux 0.0.0): Executed 151 of 151 SUCCESS (1.939 s)

Also passed locally: npm run lint, npm run typecheck, npm run test-syntax.

Perf

Headless Chromium on this agent host. One warm-up newPlot, then one timed newPlot for a single all-positive bar trace (same data shape as #8157). Parent tip without the fix vs this branch:

bars | before (ms) | after (ms) -- | -- | -- 10,000 | 267 | 132 30,000 | 1,604 | 415 60,000 | 5,707 | 702

Before: 30k→60k grows about 3.6× (quadratic). After: about 1.7× (near linear). At 60k bars, draw time drops from 5,707 ms to 702 ms.

Upstream open

Compare URL for a maintainer or the branch owner:

https://github.com/plotly/plotly.js/compare/main...short-int-ali:plotly.js:cursor/bar-zero-bar-dir-once-da7b?expand=1

After that PR opens, rename draftlogs/1_fix.md to draftlogs/<upstream#>_fix.md and fix the PR link.

No API, schema, mock, or baseline change.

Compute getZeroBarDir once per bar trace instead of once per bar.

Closes https://github.com//issues/8157 once this change lands on plotly/plotly.js (this PR is on the fork; the agent token cannot open a cross-repo PR against upstream).

Same-sign traces scanned all calcdata for every bar. That made draw time quadratic. The cached value keeps the same outside-label side for zero-extent bars (#7872).

Tests
Jasmine file: test/jasmine/tests/bar_test.js
Focus: should keep zero-value outside labels on the same side as negative bars
Command: xvfb-run --auto-servernum --server-args="-screen 0 1280x1024x24" npm run test-jasmine -- bar --nowatch --report-spec
Result: Chrome 157.0.0.0 (Linux 0.0.0): Executed 151 of 151 SUCCESS (1.939 s)
Also passed locally: npm run lint, npm run typecheck, npm run test-syntax.

Perf
Headless Chromium on this agent host. One warm-up newPlot, then one timed newPlot for a single all-positive bar trace (same data shape as #8157). Parent tip without the fix vs this branch:

bars before (ms) after (ms)
10,000 267 132
30,000 1,604 415
60,000 5,707 702
Before: 30k→60k grows about 3.6× (quadratic). After: about 1.7× (near linear). At 60k bars, draw time drops from 5,707 ms to 702 ms.

Upstream open
Compare URL for a maintainer or the branch owner:

https://github.com/plotly/plotly.js/compare/main...short-int-ali:plotly.js:cursor/bar-zero-bar-dir-once-da7b?expand=1

After that PR opens, rename draftlogs/1_fix.md to draftlogs/<upstream#>_fix.md and fix the PR link.

No API, schema, mock, or baseline change.

cursoragent and others added 3 commits November 4, 2026 02:16
Per-bar scans of same-sign calcdata made bar draw quadratic. One call per trace keeps outside zero-label direction and drops that cost to linear.

Co-authored-by: i242576 <i242576@isb.nu.edu.pk>
Pick up v4.3.0 so the pull request targets current plotly/plotly.js main.
Co-authored-by: i242576 <i242576@isb.nu.edu.pk>
Rename this file and the PR link after the change opens against plotly/plotly.js.

Co-authored-by: i242576 <i242576@isb.nu.edu.pk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants