Skip to content

ChafaWorkCell: Linear scan for contrasting color pair#334

Merged
hpjansson merged 1 commit into
hpjansson:masterfrom
leonardcser:pr-symbol-scan
Jun 9, 2026
Merged

ChafaWorkCell: Linear scan for contrasting color pair#334
hpjansson merged 1 commit into
hpjansson:masterfrom
leonardcser:pr-symbol-scan

Conversation

@leonardcser

Copy link
Copy Markdown
Contributor

chafa_work_cell_get_contrasting_color_pair previously relied on work_cell_get_dominant_channel, which performed a full counting sort over 4x64 RGBA values to determine the dominant channel and select the two extreme colors.

The result was used only for its min and max values. This change replaces the sort with a single linear scan that tracks min/max indices per channel directly.

The change is bit-identical on all test cases. It matches the old stable-sort tie-breaking behavior: the first occurrence wins for min, the last for max.

Performance

Linux x86_64, AMD Ryzen 9 7900X, GCC 15.2 -O2, perf stat -r 3

Workload Baseline Optimized Delta
default 240x120 (average) 75.4 ms 55.1 ms -27%
all 240x120 129.3 ms 112.3 ms -13%

@hpjansson hpjansson left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Looks good, but the commit message should read ChafaWorkCell: ... instead of chafa: .... By convention the latter refers to the CLI tool code.

@leonardcser leonardcser changed the title chafa: Linear scan for contrasting color pair ChafaWorkCell: Linear scan for contrasting color pair Jun 9, 2026
@leonardcser leonardcser requested a review from hpjansson June 9, 2026 18:27
@hpjansson hpjansson merged commit cf39899 into hpjansson:master Jun 9, 2026
1 check passed
@hpjansson

Copy link
Copy Markdown
Owner

Thanks a lot for these PRs and the quick edit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants