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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
