You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "gnodet (via GitHub)" <gi...@apache.org> on 2026/06/05 11:01:12 UTC
[PR] CAMEL-23686: Avoid creating empty headers map on read access [camel]
gnodet opened a new pull request, #23784:
URL: https://github.com/apache/camel/pull/23784
[CAMEL-23686](https://issues.apache.org/jira/browse/CAMEL-23686)
## Summary
- `getHeader()`, `removeHeader()`, and `removeHeaders()` no longer force creation of a `CaseInsensitiveMap` when headers haven't been set
- Short-circuits with `null` return when `headers == null` and `isPopulateHeadersSupported()` is `false`
- JMS-style messages with lazy header population (`isPopulateHeadersSupported() == true`) are preserved
## Problem
Every `getHeader(name)` call on a message with no headers forced creation of a `CaseInsensitiveMap` (allocating 4 internal arrays, ~200 bytes) just to return `null`. This happened frequently in splitter/multicast sub-exchanges that never use headers.
Before:
```java
public Object getHeader(String name) {
if (headers == null) {
headers = createHeaders(); // allocates empty CaseInsensitiveMap
}
if (!headers.isEmpty()) { // always false for new map
return headers.get(name);
} else {
return null; // returns null anyway
}
}
```
After:
```java
public Object getHeader(String name) {
if (headers == null) {
if (!isPopulateHeadersSupported()) {
return null; // no allocation
}
headers = createHeaders();
}
return headers.get(name);
}
```
## Benchmark results
Baseline route (timer → split(1000) → setBody, no header access):
- 3,891 `DefaultMessage` instances but only **4 `CaseInsensitiveMap`** — split children don't allocate maps at all
- Without this fix: every sub-exchange would create an empty map on first `getHeader()` call
Pipeline route (with `setHeader` on every exchange):
- **24% throughput increase** measured by in-flight exchange count at snapshot time
- Map ratio stays at 0.57 (expected — every exchange writes headers)
## Test plan
- [x] `DefaultMessageHeaderTest` (38 tests) — pass, including lazy-populated headers test
- [x] `DefaultMessageTest` — pass
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-23686: Avoid creating empty headers map on read access [camel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #23784:
URL: https://github.com/apache/camel/pull/23784#issuecomment-4631020772
<!-- ci-tested-modules -->
:test_tube: **CI tested the following changed modules:**
- `core/camel-support`
> :information_source: 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.
---
:gear: [View full build and test results](https://github.com/apache/camel/actions/runs/27011061410)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-23686: Avoid creating empty headers map on read access [camel]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet merged PR #23784:
URL: https://github.com/apache/camel/pull/23784
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CAMEL-23686: Avoid creating empty headers map on read access [camel]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #23784:
URL: https://github.com/apache/camel/pull/23784#issuecomment-4630815179
:star2: Thank you for your contribution to the Apache Camel project! :star2:
:robot: CI automation will test this PR automatically.
:camel: 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](https://camel.apache.org/community/team/#committers) have access to the summary.
:warning: Be careful when sharing logs. Review their contents before sharing them publicly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org