Skip to content

enhance performance of color mapping#14556

Merged
muendlein merged 6 commits into
bokeh:branch-3.8from
muendlein:enhance_color_mapping_performance
Jul 25, 2025
Merged

enhance performance of color mapping#14556
muendlein merged 6 commits into
bokeh:branch-3.8from
muendlein:enhance_color_mapping_performance

Conversation

@muendlein

@muendlein muendlein commented Jul 12, 2025

Copy link
Copy Markdown
Contributor

@muendlein

muendlein commented Jul 12, 2025

Copy link
Copy Markdown
Contributor Author

Due to string operations the current code path for color mapping is not really efficient.
Speed up with this PR is roughly 5x.

Before firefox:
firefox_before

After firefox:
firefox_after

Before chrome:
chrome_before

After chrome:
chrome_after

Code:

import numpy as np

from bokeh.io import curdoc
from bokeh.models.sources import ColumnDataSource
from bokeh.plotting import figure
from bokeh.transform import linear_cmap

n_samples = 500000

x = np.linspace(0, 10, n_samples)
y = np.sin(x)
c = np.sin(x)

cds = ColumnDataSource(data={"x": x, "y": y, "c": c})

colors = ["#37bf06", "#a0bf06", "#bfb006", "#eb9809", "#d12008", "#a80505", "#400303"]

p = figure(output_backend="webgl")
p.scatter(x="x", y="y", source=cds, line_color=None, size=5, fill_color=linear_cmap(
    "c",
    palette=colors,
    nan_color= 'rgba(255, 0, 0, 0.5)',
    low=-1,
    high=1))


curdoc().add_root(p)

@muendlein muendlein added this to the 3.x milestone Jul 12, 2025
@codecov

codecov Bot commented Jul 12, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (branch-3.8@81be65b). Learn more about missing BASE report.

Additional details and impacted files
@@              Coverage Diff              @@
##             branch-3.8   #14556   +/-   ##
=============================================
  Coverage              ?   93.28%           
=============================================
  Files                 ?      285           
  Lines                 ?    20260           
  Branches              ?        0           
=============================================
  Hits                  ?    18899           
  Misses                ?     1361           
  Partials              ?        0           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread bokehjs/src/lib/models/mappers/color_mapper.ts Outdated
Comment thread bokehjs/src/lib/models/mappers/color_mapper.ts
Comment thread bokehjs/test/unit/models/mappers/categorical_color_mapper.ts Outdated
Comment thread bokehjs/src/lib/core/uniforms.ts Outdated
@mattpap

mattpap commented Jul 21, 2025

Copy link
Copy Markdown
Contributor

The main reason for that existing approach is to preserve color values as much as possible in the output, e.g. for SVG backend. But I think performance is more important in the case of color mapping than other concerns.

@mattpap mattpap modified the milestones: 3.x, 3.8 Jul 21, 2025
@philippjfr

Copy link
Copy Markdown
Contributor

But I think performance is more important in the case of color mapping than other concerns.

Agree!

@muendlein muendlein merged commit 9ce2bba into bokeh:branch-3.8 Jul 25, 2025
28 of 29 checks passed
@github-actions

github-actions Bot commented Nov 5, 2025

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve color mapping performance

3 participants