Skip to content

ui-charts: optimize picking layer color/index conversions - #18366

Merged
emersion merged 3 commits into
devfrom
emr/optimize-picking-color
Sep 7, 2026
Merged

ui-charts: optimize picking layer color/index conversions #18366
emersion merged 3 commits into
devfrom
emr/optimize-picking-color

Conversation

@emersion

@emersion emersion commented Sep 1, 2026

Copy link
Copy Markdown
Member

Using chroma to convert from a hex color to RGBColor adds significant overhead. On my machine, it takes ~25% of the drawPicking() CPU time. See this flamechart:

out

Instead, make it so indexToColor() and colorToIndex() convert directly to/from RGBColor via bit operations.

This also allows us to drop COLORS_TO_INDICES and INDICES_TO_COLORS global state.

(A separate, first commit also adds a guard for the maximum supported index. See its commit message for details.)

@emersion
emersion requested a review from a team as a code owner September 1, 2026 14:55
@github-actions github-actions Bot added area:front Work on Standard OSRD Interface modules area:ui Work on UI labels Sep 1, 2026
@emersion emersion moved this to Awaiting merge in Board PI 21 Sep 1, 2026
@emersion emersion self-assigned this Sep 1, 2026

@hhirtz hhirtz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm although the former indexToColor wouldn't throw if index had an alpha component 🤷

@SharglutDev SharglutDev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR and the perf improvements !

Comment thread front/ui/ui-charts/src/common/helpers/colors.ts Outdated

@Yohh Yohh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, glad to see a bit less of chroma

Comment thread front/ui/ui-charts/src/common/helpers/colors.ts

@SharglutDev SharglutDev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm ✅

Check that going through indexToColor() and colorToIndex() correctly
returns the original index.

Signed-off-by: Simon Ser <contact@emersion.fr>
This function cannot handle indices above 3 bytes (one byte per
red, green, blue channel).

Signed-off-by: Simon Ser <contact@emersion.fr>
Using chroma to convert from a hex color to RGBColor adds
significant overhead. Instead, make it so indexToColor() and
colorToIndex() convert directly to/from RGBColor via bit operations.

This also allows us to drop COLORS_TO_INDICES and INDICES_TO_COLORS
global state.

Signed-off-by: Simon Ser <contact@emersion.fr>
@emersion
emersion force-pushed the emr/optimize-picking-color branch from 9cfbb70 to 10c0226 Compare September 7, 2026 08:22
@emersion
emersion enabled auto-merge September 7, 2026 08:22
@emersion
emersion added this pull request to the merge queue Sep 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 7, 2026
@emersion
emersion added this pull request to the merge queue Sep 7, 2026
Merged via the queue into dev with commit 8479e1b Sep 7, 2026
40 checks passed
@emersion
emersion deleted the emr/optimize-picking-color branch September 7, 2026 10:21
@github-project-automation github-project-automation Bot moved this from Awaiting merge to Awaiting Validation in Board PI 21 Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:front Work on Standard OSRD Interface modules area:ui Work on UI

Projects

Status: Awaiting Validation

Development

Successfully merging this pull request may close these issues.

4 participants