Repository navigation
CAMEL-27045: camel-jbang - short commands no longer open every JAR of the class path - #30199
Conversation
… the class path - The embedded plugins of the launcher are created by lambdas instead of constructor references, so a command no longer loads all the plugin classes (and Citrus and picocli through the test plugin). - The update notice and the plugin checks no longer load CamelCatalog for the version: the launcher takes it from its manifest. - quit(0) returns instead of calling System.exit when no other non-daemon thread runs: since JDK 21 System.exit asks for a System.Logger, and the JDK then looks for a LoggerFinder in every JAR. - The launcher declares aesh, ascii-table, slf4j-api and camel-catalog first, so the JARs the short commands need are first on the class path of the distribution (same JARs, other order). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
…erminal Without COLUMNS, the table width came from stty size (mode con on Windows), also when there is no terminal, where it fails or sizes a terminal the output does not go to. Starting the process costs tens of milliseconds: from JDK 24 a process start asks for a System.Logger, which makes the JDK look for a LoggerFinder in every JAR of the class path. Without a terminal the width is now the default 120 right away. 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.
The four-pronged approach is well-measured and correctly justified:
- Switching to lambdas in
PLUGINSavoids eager class loading of plugin classes at list-creation time — constructor references resolve their target class immediately, lambdas do not. - Reading
Implementation-Versionfrom the manifest inUpdateCheckeravoids instantiatingDefaultCamelCatalogon every command invocation. - The
quit(0)→ return path correctly avoidsSystem.exit'sLoggerFinderlookup on JDK 21+ while preserving shutdown-hook execution and the right exit code. - JAR ordering puts the short-command dependencies first on the class path, minimising how many JARs the JVM opens before finding a class.
Tests are well-structured: CamelJBangMainQuitTest directly exercises hasOtherNonDaemonThread with daemon/non-daemon/unstarted thread cases, and runningVersionIsTheCatalogVersion validates the manifest-fallback path.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
oscerd
left a comment
There was a problem hiding this comment.
Nice startup win, and the mechanism is the correct one.
The core move is switching the embedded plugin registry from constructor references (GeneratePlugin::new) to lazy lambdas (() -> new GeneratePlugin()). That matters because a constructor reference resolves and loads its class when the list is built, so every command loaded every plugin class, and the test plugin alone drags in Citrus and picocli, whose JARs sit far down the class path of the 341-JAR distribution. The JVM opens the class path JARs in order until it finds a class, so loading one from the bottom opens everything above it. With the lambda, the class is loaded only when a command actually selects that plugin by name through its Set.of(...) mapping, so a short command like camel ps touches none of them. The comment captures exactly that distinction, which is the easy thing to get wrong here.
The terminal-width change is the same spirit: when the output is not a terminal (!terminal.getAsBoolean()), it skips sizing a terminal the output does not go to, avoiding loading the terminal classes for a piped command. The test for the no-terminal path covers it.
Command dispatch still works because selection is by the name sets, and the lambda instantiates the right plugin on demand, so nothing that a command needs is excluded, only deferred. Good, well-reasoned optimization.
Claude Code on behalf of oscerd
|
🧪 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: 5 of 726 tested, 0 compile-only — current: 5 all testedMaveniverse Scalpel detected 5 affected modules (current approach: 5). Skip-tests mode would test 5 modules (2 direct + 0 downstream), skip tests for 0 (generated code, meta-modules) Modules Scalpel would test (5)
💡 Manual integration tests recommended:
All tested modules (14 modules, 2m 36s total)Total reactor time: 2m 36s
Top 20 slowest modules:
|
The embedded plugins are lambdas now (CAMEL-27045, #30199); the generate plugin stays out of the list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
CAMEL-27045
The short commands of the Camel CLI (
camel ps,version,get,log,stop) need classes from about 12 JARs, but on the distribution (341 JARs inlib/) they opened all of them. The JVM opens the JARs of the class path in order until it finds a class, so one class from a JAR far down opens every JAR before it. aesh's class path scan does the same; aesh is fixing that (aeshell/aesh#779MetadataProviderRegistry.useOnly, aeshell/aesh#782 lazy JUL loggers). This PR fixes the Camel side, so the aesh fixes pay off when they are released.Changes
CamelLauncherMain.PLUGINSused constructor references (GeneratePlugin::new), which load their class when the list is created. Every command loaded the 7 plugin classes, and throughTestPluginalso Citrus and picocli (JARs at position 94-291). Now lambdas, which load a plugin only when it is created.UpdateChecker(runs on every command of a web-installer install; the network check stays once a day) took the running version fromDefaultCamelCatalog, whose JAR was at position 270. It now readsImplementation-Versionfrom the launcher manifest, and falls back to the catalog when there is none.PluginHelperno longer keeps the catalog in aCamelCataloglocal, which made the verifier load the interface.System.exit(0): since JDK 21,Runtime.exitlogs throughSystem.getLogger("java.lang.Runtime"), and the firstSystem.Loggermakes the JDK look up aLoggerFinderwithServiceLoaderover the whole class path. An empty program on our class path: return from main 24 ms,System.exit(0)75 ms.CamelJBangMain.quit(0)now returns when no other non-daemon thread runs (the JVM then ends with 0 and runs the shutdown hooks); other exit codes, or other non-daemon threads, still useSystem.exit.sttywithout a terminal:TerminalWidthHelperranstty size(mode conon Windows) wheneverCOLUMNSis not exported (the usual case, shells keep it as a shell variable), also without a terminal, where it fails or sizes a terminal that the output does not go to. Starting a process costs tens of milliseconds, and from JDK 24 it also asks for aSystem.Logger(the sameLoggerFinderlookup over every JAR). Without a terminal the width is now the default 120 right away, as the Javadoc already said;COLUMNSstill wins. A table piped to another command (camel get | grep x) is now 120 wide instead of the width of the terminal.camel-jbang-core, so they are first on theClass-Pathof the launcher JAR. Before: aesh at 73, camel-catalog at 270. The set of JARs and their versions is the same (checked). Of the 62 entries that are in more than one JAR, 5 now come from another JAR:LICENSE.txt,NOTICE.txt,jandex.idx, and theother.propertiesof camel-dataweave vs camel-core-catalog, which nothing in the CLI reads as a single resource.Measured
JDK 25, macOS (Apple M4 Pro), no CDS,
COLUMNSnot set, output captured (as when an agent runs the CLI), median of 15 runs. "aesh fixes" = aesh master withuseOnlyplus a local lazy-JUL patch (aeshell/aesh#782), simulated.camel pscamel versioncamel getcamel doc timercamel catalog component --filter=kafkaOn its own this PR saves 3-13 ms: aesh 3.19.1 still scans the class path. With the aesh fixes, the short commands lose 35-43 ms. Once an aesh release has #779, the CLI also calls
MetadataProviderRegistry.useOnly(new InternalCommandMetadataRegistry())at start (follow-up).Tests
CamelJBangMainQuitTest(new): the non-daemon thread check.UpdateCheckerTest: the running version equals the catalog version.TerminalWidthHelperTest: no terminal gives the default width,COLUMNSwins and then the terminal is not checked.ps,version,get routeexit 0,nosuchexits 2;camel run --max-seconds=3ends as before (3.8-4.0 s);-Xlog:class+loadshowscamel psloading classes from 11 JARs.Claude Code on behalf of davsclaus
🤖 Generated with Claude Code
https://claude.ai/code/session_012nJsFsjqqFiwroeHRWaKbS