ammachado opened a new pull request, #28761:
URL: https://github.com/apache/camel/pull/28761

   # Description
   
   [CAMEL-26426](https://issues.apache.org/jira/browse/CAMEL-26426), tier 1 
item #3 of [CAMEL-25132](https://issues.apache.org/jira/browse/CAMEL-25132).
   
   Every exchange allocated an `EnumMap` sized for all the 
`ExchangePropertyKey` constants, and every copy cloned it. Creating it lazily 
saves nothing on its own, because `TO_ENDPOINT` is set on every send.
   
   Changes:
   
   1. **`TO_ENDPOINT` has its own field** in `AbstractExchange`, read and 
written through the existing property methods.
   2. **`internalProperties` is created when another key is set.** It is no 
longer `final`. As an `EnumMap`, it was already not safe for concurrent writes.
   3. **`ExtendedExchangeExtension.createCopyWithProperties` delegates** to 
`AbstractExchange`, so `TO_ENDPOINT` is copied in one place.
   
   This is not a public API change: `AbstractExchange` is package-private, its 
two subclasses are `final`, and the `EnumMap` constructor of `DefaultExchange` 
is package-private. So there is no upgrade guide entry.
   
   One edge case changes: with `copyInternalProperties`, a source whose 
`TO_ENDPOINT` was explicitly set to `null` no longer clears the target, because 
the field cannot tell an explicit `null` from an absent key. A source without 
the key already left the target alone.
   
   ## Measurements
   
   Single thread through a `ProducerTemplate`, no JMX, JDK 21 in a Linux arm64 
container, ParallelGC, a new JVM per run, 3 rounds alternating before and 
after. Bytes per exchange on the calling thread:
   
   | route | before | after | change |
   |---|---|---|---|
   | 1 processor | 1152 | 816 | -29% |
   | `to` one endpoint | 1168 | 832 | -29% |
   | 10 processors | 1728 | 1392 | -19% |
   | 10 processors with `maximumRedeliveries(3)` | about 2830 | 2472 | -13% |
   | `convertBodyTo` with a charset | 1232 | 1240 | +8 B |
   | multicast to 3 | 4744 | 4776 | +32 B |
   | split of 100 | about 96950 | 97752 | +0.8% |
   
   The new field adds 8 B to an exchange, so routes that still need the map are 
slightly larger. Besides split and multicast, that includes components that set 
`CHARSET_NAME`, so the gain on such routes can be smaller than on the plain 
routes above. How often each component sets it was not checked.
   
   Time per exchange: one route got slower, the 1-processor route, from about 
420 ns to about 453 ns in all 3 rounds. The cause is not known; it may be a JIT 
effect on that short route. The other routes showed no slowdown beyond noise, 
and the `to` and redelivery routes were slightly faster. Reviewers may want a 
JMH run before relying on this timing. It is not a JMH benchmark.
   
   ## Tests
   
   15 new tests in `AbstractExchangeTest`. Two failed before the change because 
the map was created. The others protect behavior a dedicated field could break: 
access by key and by name, `getInternalProperties` and `getAllProperties`, 
independent copies, `createCopyWithProperties`, `copyInternalProperties`, 
`removeProperties` with `*`, a pattern and an exclusion, and the reset of a 
pooled exchange.
   
   Verified: `camel-core`, 8516 tests, 0 failures, 44 skipped (not reviewed one 
by one), and `camel-support`, 145 tests, 0 failures. Component modules were not 
run; they use `TO_ENDPOINT` through the unchanged property methods.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
   Not run from the root folder: `core/camel-support` and `core/camel-core` 
were built and formatted, and `git status` showed only the changed files.
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code) on behalf of 
Adriano Machado (@ammachado)
   
   _This was generated by an AI agent and may contain inaccuracies. Please 
verify before relying on it._


-- 
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]

Reply via email to