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

   # Description
   
   [CAMEL-26471](https://issues.apache.org/jira/browse/CAMEL-26471), a tier 3 
item of [CAMEL-25132](https://issues.apache.org/jira/browse/CAMEL-25132), in 
the first group of its suggested order.
   
   `StopWatch.taken()` used `Duration.ofNanos(delta).toMillis()`, which 
allocates a `Duration` unless escape analysis removes it. 
`TimeUnit.NANOSECONDS.toMillis(delta)` returns the same value without depending 
on that.
   
   The gain is small. In a standalone loop on JDK 25 macOS arm64 (not JMH), 
after C2: about 1.4 ns to 0.8 ns and no allocation either way. With C1 only: 
about 5 ns to 1.8 ns and 24 B to 0 B per call.
   
   The two conversions gave the same result for 50 million random values and 
for the boundary values, including negatives, `Long.MIN_VALUE` and 
`Long.MAX_VALUE`.
   
   ## Tests
   
   `testTakenTruncatesNanosToMillis` uses `TimeSource.install` for an exact 
clock. It passes on the old code too, as this change must not alter results. It 
failed when I replaced the conversion with rounding and with floor division.
   
   Verified: `camel-util`, 326 tests, 0 failures. Other modules were not run 
locally.
   
   # 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: I ran the `camel-util` module tests, and `git 
status` showed only the two changed files afterwards.
   
   # 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