Repository navigation
CAMEL-26391: camel-core - MessageSupport: create the message traits map lazily - #28650
Conversation
…ap lazily Every message allocated an EnumMap for its traits, and an exchange has one to three messages. Traits are only set for redelivery, data types (when useDataType is enabled or a data type is set) and attachments, so most messages never use the map. Create it when the first trait is set. Measured locally (JDK 25 on macOS, single thread, after warm-up): new DefaultMessage allocates 48 B instead of 120 B. Part of CAMEL-25132 (tier 1, item #3, traits part). _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._ Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 576 of 708 tested, 27 compile-only — current: 576 all testedMaveniverse Scalpel detected 576 affected modules (current approach: 576). Skip-tests mode would test 576 modules (1 direct + 575 downstream), skip tests for 27 (generated code, meta-modules) Modules Scalpel would test (576)
Modules with tests skipped (27)
|
davsclaus
left a comment
There was a problem hiding this comment.
Every traits access is null-guarded and the field is private. Dropping final loses safe publication in theory, but exchange handoff between threads goes through queues/executors and EnumMap mutation was never thread-safe, so I see no new realistic risk. LGTM.
Reviewed with Claude Code on behalf of @davsclaus. This review was generated by an AI agent and may contain inaccuracies; please verify all suggestions before applying.
Description
CAMEL-26391, tier 1 item #3 (traits part) of CAMEL-25132.
Every
MessageSupportallocated anEnumMap<MessageTrait, Object>for its traits, and an exchange has one to three messages. Traits are only set for redelivery (by some consumers), data types (whenuseDataTypeis enabled or a data type is set explicitly) and attachments, so most messages never use the map. This change creates it when the first trait is set. The field is private and only used by the trait methods ofMessageSupport.Measured locally (JDK 25 on macOS, single thread, after warm-up,
ThreadMXBeanallocated bytes):new DefaultMessageallocates 48 B instead of 120 B.The field is no longer
final. Messages were not thread safe before either (EnumMapis not), so this does not add a new risk.New
MessageSupportTraitsTest(camel-support had no test for these methods). It covers reading and removing traits before any is set, a trait set with anullpayload still counting as set,reset, andcopyFromkeeping the data type and copying the attachments, also for a message without traits. These tests pass before and after the change.Verified: 10 tests in camel-support (
*Message*Test,*DataType*Test) and 279 in camel-core (*Message*Test,*DataType*Test,*Attachment*Test,*Transformer*Test,*Redeliver*Test,*Copy*Test,*InputType*Test,*OutputType*Test). The 2 skipped tests are*ManualTeststress tests.Target
mainbranch)Tracking
Apache Camel coding standards and style
I checked that each commit in the pull request has a meaningful subject line and body.
I have run
mvn clean install -DskipTestslocally from root folder and I have committed all auto-generated changes.Not from the root folder: I built and installed the changed module (camel-support), ran
mvn formatter:format impsort:sorton the changed modules, andgit statuswas clean afterwards.AI-assisted contributions
Co-authored-bytrailers) and the PR description identifies the AI tool used.The code and this description were written with Claude Code (Claude Opus 5.5) and reviewed by me.
🤖 Generated with 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.