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

   [CAMEL-27045](https://issues.apache.org/jira/browse/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 in 
`lib/`) 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#779 `MetadataProviderRegistry.useOnly`, aeshell/aesh#782 lazy JUL 
loggers). This PR fixes the Camel side, so the aesh fixes pay off when they are 
released.
   
   ### Changes
   
   - **Embedded plugins**: `CamelLauncherMain.PLUGINS` used constructor 
references (`GeneratePlugin::new`), which load their class when the list is 
created. Every command loaded the 7 plugin classes, and through `TestPlugin` 
also Citrus and picocli (JARs at position 94-291). Now lambdas, which load a 
plugin only when it is created.
   - **Version without the catalog**: `UpdateChecker` (runs on every command of 
a web-installer install; the network check stays once a day) took the running 
version from `DefaultCamelCatalog`, whose JAR was at position 270. It now reads 
`Implementation-Version` from the launcher manifest, and falls back to the 
catalog when there is none. `PluginHelper` no longer keeps the catalog in a 
`CamelCatalog` local, which made the verifier load the interface.
   - **No `System.exit(0)`**: since JDK 21, `Runtime.exit` logs through 
`System.getLogger("java.lang.Runtime")`, and the first `System.Logger` makes 
the JDK look up a `LoggerFinder` with `ServiceLoader` over 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 use `System.exit`.
   - **JAR order**: the launcher declares aesh, ascii-table, slf4j-api and 
camel-catalog before `camel-jbang-core`, so they are first on the `Class-Path` 
of 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 the `other.properties` of 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, median of 15 runs. "aesh fixes" = aesh 
master with `useOnly` plus a local lazy-JUL patch (aeshell/aesh#782), simulated.
   
   | command | main | this PR | old order + aesh fixes | this PR + aesh fixes |
   |---|---|---|---|---|
   | `camel ps` | 141 ms | 138 ms | 112 ms | 105 ms |
   | `camel version` | 149 ms | 143 ms | 142 ms | 112 ms |
   | `camel get` | 195 ms | 186 ms | 182 ms | 158 ms |
   | `camel doc timer` | 187 ms | 183 ms | 187 ms | 180 ms |
   
   On its own this PR saves 3-9 ms: aesh 3.19.1 still scans the class path. 
With the aesh fixes, `ps` and `version` lose 35-37 ms. Once an aesh release has 
#779, the CLI also calls `MetadataProviderRegistry.useOnly(new 
InternalCommandMetadataRegistry())` at start (follow-up).
   
   `camel doc` (and other table output) also runs `stty size` when `COLUMNS` is 
not exported, and starting a process does the same `LoggerFinder` lookup (JDK 
24+): 188 ms vs 144 ms with `COLUMNS=120`. Not in this PR, as skipping it 
changes the width when only stdout is piped.
   
   ### Tests
   
   - `CamelJBangMainQuitTest` (new): the non-daemon thread check.
   - `UpdateCheckerTest`: the running version equals the catalog version.
   - camel-jbang-core: 3100 run, 0 failures (the 2 `DoctorRepositoryTest` 
failures under a scratch local repo pass on their own).
   - camel-launcher: 419 run, 0 failures, 47 skipped.
   - Distribution: `ps`, `version`, `get route` exit 0, `nosuch` exits 2; 
`camel run --max-seconds=3` ends as before (3.8-4.0 s); `-Xlog:class+load` 
shows `camel ps` loading classes from 11 JARs.
   
   _Claude Code on behalf of davsclaus_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_012nJsFsjqqFiwroeHRWaKbS
   


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