Skip to content

CAMEL-23693: Optimize CaseInsensitiveMap hash for ASCII keys#23779

Merged
gnodet merged 1 commit into
apache:mainfrom
gnodet:camel-23693-optimize-casemap-hash
Jun 5, 2026
Merged

CAMEL-23693: Optimize CaseInsensitiveMap hash for ASCII keys#23779
gnodet merged 1 commit into
apache:mainfrom
gnodet:camel-23693-optimize-casemap-hash

Conversation

@gnodet
Copy link
Copy Markdown
Contributor

@gnodet gnodet commented Jun 5, 2026

CAMEL-23693

Summary

Optimize the CaseInsensitiveMap hash function and eliminate redundant hash computations introduced in CAMEL-23691.

  • ASCII fast-path in hash: c += 32 for A-Z instead of Character.toLowerCase(Character.toUpperCase(c)) per character. Full Unicode two-step fold only for non-ASCII (c >= 128)
  • Single-hash put(): compute hash once, reuse for deduplication lookup, find, and bucket insertion (was 3 separate hash computations)
  • Single-hash remove(): inline chain walk with one hash computation (was 2)

Benchmark (18 typical headers, 2M iterations)

Scenario Before After vs TreeMap (old impl)
put/get/containsKey/remove 9.0M ops/s 33.3M ops/s 1.2x faster
Exchange copy (create+populate+copy) 490K copies/s 1.9M copies/s 1.1x faster
Get-heavy (10 lookups/iter) 16.9M lookups/s 39.8M lookups/s 1.7x faster

Test plan

  • CaseInsensitiveMapTest — 32 tests pass
  • DefaultMessageHeaderTest — 38 tests pass

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet requested a review from davsclaus June 5, 2026 09:14
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@github-actions github-actions Bot added the core label Jun 5, 2026
@gnodet gnodet marked this pull request as ready for review June 5, 2026 09:40
@gnodet gnodet requested a review from oscerd June 5, 2026 09:40
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

🧪 CI tested the following changed modules:

  • core/camel-util

ℹ️ Dependent modules were not tested because the total number of affected modules exceeded the threshold (50). Use the test-dependents label to force testing all dependents.


⚙️ View full build and test results

Copy link
Copy Markdown
Contributor

@davsclaus davsclaus left a comment

Choose a reason for hiding this comment

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

Clean performance follow-up to #23766. The ASCII fast-path (c += 32 for A-Z) is correct and produces identical hash values as the previous Character.toLowerCase(Character.toUpperCase(c)) for ASCII, with full Unicode fallback for non-ASCII. Single-hash put() and remove() eliminate redundant computations on the hot path. CI is green, existing tests cover correctness.

This review does not replace specialized AI review tools (CodeRabbit, Sourcery) or static analysis (SonarCloud).

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

@gnodet gnodet merged commit 7ac20cb into apache:main Jun 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants