Skip to content

Avoid allocating color name arrays for lookup - #148

Open
OskarEichler wants to merge 1 commit into
ku1ik:masterfrom
OskarEichler:codex/rainbow-color-lookup
Open

Avoid allocating color name arrays for lookup#148
OskarEichler wants to merge 1 commit into
ku1ik:masterfrom
OskarEichler:codex/rainbow-color-lookup

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Use the immutable color-name hashes directly for membership checks instead of allocating NAMES.keys arrays and linearly scanning them for every color lookup.

Public color_names results, ANSI-over-X11 precedence, errors and generated SGR output are unchanged.

Verification

  • Existing suite: 220 examples, 0 failures on Ruby 3.2.11 and 4.0.6.
  • RuboCop: 15 files, 0 offenses on both Rubies.
  • External model: 763 behavior checks per Ruby across every ANSI/X11 name, both grounds, constructor/factory/disabled paths, precedence, invalid names and public-list isolation.
  • Focused Ruby 4 microbenchmark, 20,000 calls/sample: X11 median 41.51 -> 21.63 ms and 400,000 -> 340,000 allocations; disabled X11 11.34 -> 1.66 ms and 40,000 -> 20,000 allocations; ANSI 13.19 -> 12.31 ms and 260,000 -> 220,000 allocations. Ruby 3.2 showed comparable allocation reductions. This is a focused microbenchmark, not application throughput.
  • Rebuilt gem: 14 expected files and successful packaged loads on both Rubies.
  • No test files changed.

Compatibility

No breaking change.

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.

1 participant