Repository navigation
chore: camel-jbang - local times without the time zone rules of java.time (get health, log, get sql-trace) - #30213
Conversation
…time (get health, log, get sql-trace) ZoneId.systemDefault(), and parsing a time with a region such as [Europe/Paris], load the time zone rules of java.time, and the JDK looks for their providers with a ServiceLoader in every JAR of the class path (about 50 ms with the 340 JARs of the CLI distribution). CliTimes takes the offset of the default TimeZone at that time instead, which gives the same local time, and parses an ISO date-time from its offset. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
gnodet-bot
left a comment
There was a problem hiding this comment.
LGTM. No issues found.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
🧪 CI tested the following changed modules:
🔁 1 test passed only after a retry on JDK 21 (1 retried attempt) Recovered flaky tests on JDK 21 (1)
🔬 Scalpel shadow comparison — Scalpel: 6 of 726 tested, 8 compile-only — current: 6 all testedMaveniverse Scalpel detected 6 affected modules (current approach: 6). Skip-tests mode would test 6 modules (2 direct + 5 downstream), skip tests for 8 (generated code, meta-modules) Modules Scalpel would test (6)
Modules with tests skipped (8)
💡 Manual integration tests recommended:
All tested modules (15 modules, 3m 32s total)Total reactor time: 3m 32s
Top 20 slowest modules:
|
oscerd
left a comment
There was a problem hiding this comment.
Neat micro-optimization, and it keeps the times correct.
ZoneId.systemDefault() and parsing a region id like [Europe/Paris] pull in java.time's zone rules, which makes the JDK run a ServiceLoader over every JAR on the class path looking for ZoneRulesProvider, about 50 ms with the 340 JARs of the distribution on a command that otherwise needs a dozen. Avoiding that on a short command is worth doing.
The substitution is sound: TimeZone.getDefault().getOffset(epochMillis) reads the same JDK tzdb data and returns the offset in effect at that instant, so it is DST-aware (the offset is computed for the actual date, not a fixed raw offset), and wrapping it as a ZoneOffset gives the same local time java.time would have produced, without triggering the provider scan. So this is a faster path to the same answer, not an approximation. Consistent with the other short-command startup work. Good.
Claude Code on behalf of oscerd
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
ZoneId.systemDefault(), and parsing a time with a region such as[Europe/Paris], load the time zone rules of java.time. The JDK then looks for their providers (ZoneRulesProvider) with aServiceLoaderin every JAR of the class path: about 50 ms with the 340 JARs of the CLI distribution, on a short command that otherwise needs a dozen JARs. Found while working on the startup of the short commands (CAMEL-26935).Change
CliTimes(camel-jbang-run) gives local times without those rules: the offset of the defaultTimeZoneat that time (both read the tzdb data of the JDK, so the local time is the same, also around daylight saving changes), and the epoch millis of an ISO date-time from its offset (the region in brackets is left out; a text without an offset still goes toZonedDateTime.parse).It is used where a short command printed a local time or parsed one:
camel get health: the SINCE column parsed the times of the health checks withZonedDateTime.parse(with region) andZonedDateTime.now().camel log: the tip about the previous run (PreviousRun), whose formatter calledZoneId.systemDefault()when the class was loaded.camel get sql-trace: the TIME column.The other uses of java.time zones in the CLI are in commands that do much more anyway (run, export, the AI tools, chaos explore).
Measured on a small program with the class path of the distribution: formatting a local time with
ZoneId.systemDefault()60 ms, withCliTimes7 ms (SimpleDateFormat21 ms, it loads locale data).Measured
JDK 25, macOS (Apple M4 Pro), through
camel.sh(with its CDS archive), median of 15 runs; CPU time (user + system), with the wall time in brackets, as the machine was busy:camel get health(one integration)camel log(tip about a previous run)camel loggains little on main today, as aesh's class path scan (aeshell/aesh#779) and its JUL loggers (aeshell/aesh#782) open every JAR first; with those fixed, and #30199, the zone rules were 30 ms of it.Tests
CliTimesTest(new): the same local time asZoneId.of(zone)for Copenhagen, New York, Kolkata, Lord Howe (half hour daylight saving) and UTC, at the second before and after the 2026 daylight saving changes of Europe and the US and the April one of Lord Howe; parsing the text of aZonedDateTimewith and without region, with an offset andZ; a text that is not a date-time.CliTimesTest,PreviousRunTest,PreviousRunLogTest; camel-jbang-core:ListHealthTest,ListSqlTraceTest,CamelLogActionTestand the process tests: all pass.-Xlog:class+loadshows noZoneRulesProviderforget healthand thelogtip (main: loaded); their output is the same as on main.Claude Code on behalf of davsclaus
🤖 Generated with Claude Code
https://claude.ai/code/session_012nJsFsjqqFiwroeHRWaKbS