[
https://issues.apache.org/jira/browse/CAMEL-27045?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18145601#comment-18145601
]
Claus Ibsen commented on CAMEL-27045:
-------------------------------------
PR: https://github.com/apache/camel/pull/30199 (embedded plugins created by
lambdas, version from the launcher manifest, no System.exit for exit code 0,
hot JARs first on the class path). The useOnly call at start follows once an
aesh release has aeshell/aesh#779.
_Claude Code on behalf of Claus Ibsen_
> camel-jbang - short commands open every JAR of the class path (embedded
> plugins, System.exit)
> ---------------------------------------------------------------------------------------------
>
> Key: CAMEL-27045
> URL: https://issues.apache.org/jira/browse/CAMEL-27045
> Project: Camel
> Issue Type: Improvement
> Components: camel-jbang
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Priority: Minor
> Fix For: 4.24.0
>
>
> The short commands of the Camel CLI ({{camel ps}}, {{camel version}}, {{camel
> get}}) take about 140 ms. On the distribution (341 JARs in lib/), opening
> every JAR of the class path costs about 30 ms of that. aesh can now skip its
> class path scan (aeshell/aesh#779, {{MetadataProviderRegistry.useOnly}}) and
> is asked to stop starting JUL (aeshell/aesh#782), but the CLI itself opens
> every JAR in two other places, so neither change saves anything until these
> two are fixed as well.
> h3. 1. The embedded plugins are loaded at start
> {{CamelLauncherMain.PLUGINS}} is a static list of {{GeneratePlugin::new}},
> {{KubernetesPlugin::new}}, ... A constructor reference loads its class when
> the list is built, so every command loads the 7 plugin classes, and through
> {{TestPlugin}} also Citrus ({{org.citrusframework.jbang.cli.Printer}}) and
> picocli. {{PluginHelper}} also loads {{CamelCatalog}}. The furthest JAR is at
> position 291 of 341, and a class from a JAR far down the class path opens
> every JAR before it.
> Fix: {{() -> new GeneratePlugin()}} (a lambda loads the class only when
> called) or class names, and keep {{CamelCatalog}} out of the start path.
> h3. 2. System.exit asks for a System.Logger
> Since JDK 21, {{Runtime.exit}} logs the exit through
> {{System.getLogger("java.lang.Runtime")}}. The first {{System.Logger}} makes
> the JDK look up a {{LoggerFinder}} with {{ServiceLoader}}, which reads every
> JAR. {{CamelJBangMain.quit}} calls {{System.exit}} for every command, also
> for exit code 0.
> An empty program on the 341-JAR class path: return from main 24 ms,
> {{System.exit(0)}} 75 ms (30 ms with a small class path).
> {{jdk.system.logger.level}} does not avoid the lookup.
> Fix to decide: return from main for exit code 0 when no non-daemon thread is
> left (the JVM then ends without {{Runtime.exit}}), and keep {{System.exit}}
> for other codes.
> h3. Measured
> JDK 25, macOS (Apple M4 Pro), no CDS, median of 20 runs, aesh master with
> {{useOnly}} and lazy JUL loggers (local patch). Items 1 and 2 were simulated:
> the used JARs first on the class path, and {{Runtime.halt}} in {{quit}}
> (measurement only, it skips the shutdown hooks).
> ||setup||camel ps||camel version||
> |today|141 ms|145 ms|
> |items 1 + 2 done, aesh scan|139 ms|144 ms|
> |items 1 + 2 done, aesh useOnly + lazy JUL|105 ms|116 ms|
> The CLI also needs to call {{MetadataProviderRegistry.useOnly(new
> InternalCommandMetadataRegistry())}} at start, once an aesh release has #779
> (aesh 3.19.2 or later).
> _Claude Code on behalf of Claus Ibsen_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)