René's URL Explorer Experiment


Title: [BUG]: Bar traces draw in O(n²) time since v4.0.0 (getZeroBarDir runs once per bar) · Issue #8157 · plotly/plotly.js · GitHub

Open Graph Title: [BUG]: Bar traces draw in O(n²) time since v4.0.0 (getZeroBarDir runs once per bar) · Issue #8157 · plotly/plotly.js

X Title: [BUG]: Bar traces draw in O(n²) time since v4.0.0 (getZeroBarDir runs once per bar) · Issue #8157 · plotly/plotly.js

Description: Description Since v4.0.0, drawing a bar trace takes O(n²) time whenever all bar values have the same sign, which is the common case for counts, totals, and revenue. 60k bars take ~3.7 s in v4.x versus ~0.3 s in v3.7.0, and 100k bars free...

Open Graph Description: Description Since v4.0.0, drawing a bar trace takes O(n²) time whenever all bar values have the same sign, which is the common case for counts, totals, and revenue. 60k bars take ~3.7 s in v4.x ver...

X Description: Description Since v4.0.0, drawing a bar trace takes O(n²) time whenever all bar values have the same sign, which is the common case for counts, totals, and revenue. 60k bars take ~3.7 s in v4.x ver...

Opengraph URL: https://github.com/plotly/plotly.js/issues/8157

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[BUG]: Bar traces draw in O(n²) time since v4.0.0 (getZeroBarDir runs once per bar)","articleBody":"### Description\n\nSince v4.0.0, drawing a `bar` trace takes O(n²) time whenever all bar values have the same sign, which is the common case for counts, totals, and revenue. 60k bars take ~3.7 s in v4.x versus ~0.3 s in v3.7.0, and 100k bars freeze the page for close to a minute (measured in an app that embeds plotly.js 4.1.2).\n\nThe cause is in `src/traces/bar/plot.js`. Since #7872, `appendBarText()` calls `getZeroBarDir(cd, isHorizontal, xa, ya)` for **every bar**. `getZeroBarDir` loops over all of `cd` and only returns early once it has seen both a positive and a negative value:\n\n```js\nfunction appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, r, overhead, opts, makeOnCompleteCallback) {\n    ...\n    var zeroBarDir = getZeroBarDir(cd, isHorizontal, xa, ya);   // O(n), runs once per bar\n\n    var text = getText(fullLayout, cd, i, xa, ya);\n    textPosition = getTextPosition(trace, i);\n    ...\n    if (!text || textPosition === 'none' || ...) {\n        bar.select('text').remove();\n        return;\n    }\n```\n\n```js\nfunction getZeroBarDir(cd, isHorizontal, xa, ya) {\n    var hasPositive = false;\n    var hasNegative = false;\n\n    for (var i = 0; i \u003c cd.length; i++) {\n        var s = cd[i].s;\n        if (s > 0) {\n            hasPositive = true;\n        } else if (s \u003c 0) {\n            hasNegative = true;\n        }\n        if (hasPositive && hasNegative) {\n            return 0;\n        }\n    }\n    ...\n}\n```\n\nThe call runs before the `!text || textPosition === 'none'` early return. So traces **without any text**, and traces with `textposition: 'none'`, pay the quadratic cost too. Mixed-sign data exits the loop almost immediately, which is why it stays fast.\n\nA Chrome CPU profile of a 30k-bar `newPlot` attributes 2.6 s of the 3.4 s long task to this function.\n\n### Screenshots/Video\n\nN/A (performance). `Plotly.newPlot` timings for a single bar trace in headless Chromium 156 on an Apple M4 (macOS). Each cell is one run in a fresh page:\n\n| plotly.js | bars | all positive (ms) | mixed sign (ms) | all positive, `textposition: 'none'` (ms) |\n|---|---:|---:|---:|---:|\n| 3.7.0 | 10,000 | 93 | 86 | 76 |\n| 3.7.0 | 30,000 | 175 | 179 | 172 |\n| 3.7.0 | 60,000 | 299 | 304 | 301 |\n| 4.0.0 | 10,000 | 184 | 83 | 184 |\n| 4.0.0 | 30,000 | 1,052 | 191 | 1,134 |\n| 4.0.0 | 60,000 | 3,716 | 350 | 3,698 |\n| 4.2.0 | 10,000 | 189 | 105 | 186 |\n| 4.2.0 | 30,000 | 1,043 | 195 | 1,048 |\n| 4.2.0 | 60,000 | 3,736 | 386 | 3,701 |\n\nDoubling the bar count roughly quadruples the time on 4.x, while 3.7.0 and mixed-sign data scale linearly.\n\n### Steps to reproduce\n\nOpen this page in Chrome and look at the console. Switching the version in the script URL to `3.7.0`, or making some `y` values negative, makes it fast again.\n\n```html\n\u003c!doctype html>\n\u003chtml>\n\u003chead>\n  \u003cmeta charset=\"utf-8\">\n  \u003cscript src=\"https://cdn.jsdelivr.net/npm/plotly.js-dist-min@4.2.0/plotly.min.js\">\u003c/script>\n\u003c/head>\n\u003cbody>\n  \u003cdiv id=\"plot\" style=\"width:900px;height:450px\">\u003c/div>\n  \u003cscript>\n    const n = 60000;\n    const x = Array.from({ length: n }, (_, i) => i);\n    const y = Array.from({ length: n }, (_, i) => 1 + ((i * 7919) % 100)); // all positive\n    const t0 = performance.now();\n    Plotly.newPlot('plot', [{ type: 'bar', x, y }]).then(() =>\n      console.log(`newPlot: ${Math.round(performance.now() - t0)} ms`)\n    );\n  \u003c/script>\n\u003c/body>\n\u003c/html>\n```\n\nThe same happens from Python with `px.bar(x=np.arange(60_000), y=np.random.rand(60_000)).show()`, since plotly.py 7.1.0 bundles plotly.js 4.1.1.\n\n### Notes\n\n- **Introduced by** #7872 (\"fix(bar): prevent outside text labels from overlapping tilted axis ticks\"), commits 6b1363e5a / f291d70fb / 79c20f8ed. It ships in v4.0.0 and is still present in v4.2.0 and `main`.\n- **Suggested fix:** compute the zero-bar direction once per trace and pass it into `appendBarText`. For example, compute it in `plotBars` before iterating the bars and pass it through `opts`, or cache it on `cd[0]`. Moving the call below the `!text` / `textposition === 'none'` early return would also help traces without text, but traces with text would remain quadratic.\n- **Workaround:** none from the public API, since `textposition: 'none'` does not avoid the call.\n- Found while benchmarking chart rendering in Streamlit, which bundles plotly.js 4.1.2 for `st.plotly_chart`.\n","author":{"url":"https://github.com/lukasmasuch","@type":"Person","name":"lukasmasuch"},"datePublished":"2026-10-30T19:35:45Z","url":"https://github.com/plotly/plotly.js/issues/8157"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:5d07777e-6b80-2347-9d8d-c81872850987
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCDE8:299992:841E57:AE9513:6B01AE36
html-safe-nonce83279136fde2b840075f2a19ab185a7aa1db2cad912f994cb5e48b6b4a362512
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDREU4OjI5OTk5Mjo4NDFFNTc6QUU5NTEzOjZCMDFBRTM2IiwidmlzaXRvcl9pZCI6IjQyMzQwMjIwNDI1Nzc1MTQwMzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac52d42927c010c62a0d78f255c204f17257199e4f49631920f1ca9bf336ae9184
hovercard-subject-tagissue:6125779379
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/plotly/plotly.js/8157/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ec67ce6cf3c9ae6a744d1202b2dc74877c274877fe596a8827d2e6f21ee3b32d/plotly/plotly.js/issues/8157
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ec67ce6cf3c9ae6a744d1202b2dc74877c274877fe596a8827d2e6f21ee3b32d/plotly/plotly.js/issues/8157
og:image:altDescription Since v4.0.0, drawing a bar trace takes O(n²) time whenever all bar values have the same sign, which is the common case for counts, totals, and revenue. 60k bars take ~3.7 s in v4.x ver...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamelukasmasuch
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/plotly/plotly.js git https://github.com/plotly/plotly.js.git
octolytics-dimension-user_id5997976
octolytics-dimension-user_loginplotly
octolytics-dimension-repository_id45646037
octolytics-dimension-repository_nwoplotly/plotly.js
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id45646037
octolytics-dimension-repository_network_root_nwoplotly/plotly.js
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/plotly/plotly.js/issues/8157#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fplotly%2Fplotly.js%2Fissues%2F8157
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fplotly%2Fplotly.js%2Fissues%2F8157
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=plotly%2Fplotly.js
Reloadhttps://github.com/plotly/plotly.js/issues/8157
Reloadhttps://github.com/plotly/plotly.js/issues/8157
Reloadhttps://github.com/plotly/plotly.js/issues/8157
plotlyhttps://github.com/plotly
plotly.jshttps://github.com/plotly/plotly.js
Codehttps://github.com/plotly/plotly.js
Issues726 (726)https://github.com/plotly/plotly.js/issues
Pull requests84 (84)https://github.com/plotly/plotly.js/pulls
Actionshttps://github.com/plotly/plotly.js/actions
Security and qualityhttps://github.com/plotly/plotly.js/security
Insightshttps://github.com/plotly/plotly.js/insights
https://github.com/plotly/plotly.js
New issuehttps://github.com/login?return_to=https://github.com/plotly/plotly.js/issues/8157
New issuehttps://github.com/login?return_to=https://github.com/plotly/plotly.js/issues/8157
short-int-ali/plotly.js#1https://github.com/short-int-ali/plotly.js/pull/1
[BUG]: Bar traces draw in O(n²) time since v4.0.0 (getZeroBarDir runs once per bar)https://github.com/plotly/plotly.js/issues/8157#top
short-int-ali/plotly.js#1https://github.com/short-int-ali/plotly.js/pull/1
https://github.com/KoolADE85
P3backloghttps://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22P3%22
bugsomething brokenhttps://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22bug%22
plotly-internalhttps://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22plotly-internal%22
size: 3https://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22size%3A%203%22
https://github.com/lukasmasuch
lukasmasuchhttps://github.com/lukasmasuch
on Oct 30, 2026https://github.com/plotly/plotly.js/issues/8157#issue-6125779379
#7872https://github.com/plotly/plotly.js/pull/7872
fix(bar): prevent outside text labels from overlapping tilted axis ticks #7872https://github.com/plotly/plotly.js/pull/7872
6b1363ehttps://github.com/plotly/plotly.js/commit/6b1363e5a43a996007038188e51c0525691331b6
f291d70https://github.com/plotly/plotly.js/commit/f291d70fb79d2e5b077aecf8eb05ec335437329a
79c20f8https://github.com/plotly/plotly.js/commit/79c20f8ed47ddc8c9ca66859e5aee489860063b1
https://github.com/short-int-ali
short-int-alihttps://github.com/short-int-ali
on Nov 2, 2026https://github.com/plotly/plotly.js/issues/8157#issuecomment-6580800693
https://github.com/KoolADE85
KoolADE85https://github.com/KoolADE85
on Nov 2, 2026https://github.com/plotly/plotly.js/issues/8157#issuecomment-6587673270
@lukasmasuchhttps://github.com/lukasmasuch
libraries-dashboardhttps://github.com/apps/libraries-dashboard
P3backloghttps://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22P3%22
size: 3https://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22size%3A%203%22
bugsomething brokenhttps://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22bug%22
on Nov 2, 2026https://github.com/plotly/plotly.js/issues/8157#event-34952137612
https://github.com/lukasmasuch
lukasmasuchhttps://github.com/lukasmasuch
on Nov 2, 2026https://github.com/plotly/plotly.js/issues/8157#issuecomment-6588333725
@KoolADE85https://github.com/KoolADE85
https://github.com/KoolADE85
KoolADE85https://github.com/KoolADE85
on Nov 2, 2026https://github.com/plotly/plotly.js/issues/8157#issuecomment-6589452098
KoolADE85https://github.com/KoolADE85
on Nov 2, 2026https://github.com/plotly/plotly.js/issues/8157#event-34959953936
https://github.com/short-int-ali
short-int-alihttps://github.com/short-int-ali
on Nov 13, 2026https://github.com/plotly/plotly.js/issues/8157#issuecomment-6853910156
@KoolADE85https://github.com/KoolADE85
camdecosterhttps://github.com/camdecoster
plotly-internalhttps://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22plotly-internal%22
on Nov 16, 2026https://github.com/plotly/plotly.js/issues/8157#event-36323593502
https://github.com/camdecoster
camdecosterhttps://github.com/camdecoster
on Nov 16, 2026https://github.com/plotly/plotly.js/issues/8157#issuecomment-6928341001
@short-int-alihttps://github.com/short-int-ali
Sign up for freehttps://github.com/signup?return_to=https://github.com/plotly/plotly.js/issues/8157
Sign in to commenthttps://github.com/login?return_to=https://github.com/plotly/plotly.js/issues/8157
KoolADE85https://github.com/KoolADE85
P3backloghttps://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22P3%22
bugsomething brokenhttps://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22bug%22
plotly-internalhttps://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22plotly-internal%22
size: 3https://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22size%3A%203%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.