plotly / plotly/plotly.js

[BUG]: Color Translation is Costly

Open
#8,054 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug P2 size: 1
Dominant language
JavaScript
Stars
18.3k
Forks
2k
Avg merge
2d 12h
Merged PRs (30d)
28

Description

Description

When rendering a scatter trace, we run rgb(color_string) and parse(color_string) four times for every mark. For the vast majority of scatter charts, this is wasteful re-computation.

Surprisingly, this string parsing appears to be a serious bottleneck. Removing it seems to provide a 2x speed improvement for charts with large numbers of marks.

Screenshots/Video
Image
Steps to reproduce

Run npm start.
In the the console run:

const gd = document.getElementById('graph');
const n = 1e5, x = new Float64Array(n), y = new Float64Array(n);
for (let i = 0; i < n; i++) { x[i] = i; y[i] = Math.sin(i / 500); }
const runs = [];
for (let k = 0; k < 5; k++) {
    await Plotly.purge(gd);
    const t = performance.now();
    await Plotly.newPlot(gd, [{type: 'scatter', mode: 'markers', x, y}],
        {width: 900, height: 600}, {displayModeBar: false});
    runs.push(+(performance.now() - t).toFixed(1));
}
runs.sort((a, b) => a - b);
console.log('median', runs[2], runs);

See the numbers. Then test with the memoization PR I've put up and notice the lower numbers.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the scatter trace rendering path that calls rgb(color_string) and parse(color_string); compare it with the memoization PR mentioned in the report. Reproduce the 100,000-mark benchmark from the issue, then confirm the optimized run retains rendering behavior and improves median timing.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data-visualization, performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.