perf(points): strip alpha on unique colours, not once per point#692
Merged
Conversation
In the categorical datashader points path, _render_points stripped the alpha
component from every point's hex colour:
color_vector = np.asarray([_hex_no_alpha(c) for c in color_vector])
_hex_no_alpha is a Python per-string parser, so this ran once per point even
though a categorical colour vector holds only a handful of distinct strings.
Deduplicate via np.unique(return_inverse=True): strip alpha on the unique
values and map back.
Output is unchanged (RGBA buffers byte-identical to main across 6 categorical
point scenarios: genes/cat7, palette, groups, na_color, alpha). The hex strip
drops from ~67 ms to ~6 ms at 50k points; end-to-end render_points is ~9%
faster at 50k and ~16% at 200k, scaling with point count.
np.unique(return_inverse=True) already yields a 1-D inverse for the 1-D color_vector, so reshape(-1) was a no-op. Output unchanged (6-scenario parity holds).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Second item from the profiling write-up in #690 (after the shapes patch-build fix in #691).
In the categorical datashader path of
_render_points, the alpha component was strippedfrom every point's hex colour:
_hex_no_alphais a Python per-string parser/validator, so this ran once per point — buta categorical colour vector only holds a handful of distinct strings (one per category).
Change
Deduplicate with
np.unique(..., return_inverse=True): strip alpha on the unique valuesand map back.
(
reshape(-1)guards against the numpy 2.0return_inverseshape change.)Correctness — byte-identical output
Rendered 6 categorical point scenarios on this branch and on
main, comparing the AggRGBA buffers exactly (
np.array_equal): all identical.Performance
The hex strip drops from ~67 ms to ~6 ms at 50k points (the operation is bit-identical).
End-to-end
render_points(color=…):The saving scales with point count.
Notes
test_plot_*visual baselinesrun on CI; output is byte-identical to
main, so they should pass unchanged.Addresses the points item in #690.