Repository navigation
chore(benchmarks): run the JMH benchmarks with quiet logging - #1083
Merged
Merged
Conversation
Only the manual harness applied logback-benchmark.xml. A forked JMH JVM found no Logback configuration, fell back to Logback's default and printed every engine DEBUG line to the console: 32.8 MB for one CanonicalRender fork, 22.2 MB for the four DocxExport.docx shapes, 25.9 MB for ColdStart, and the logging was inside the measured region. Every JMH benchmark now extends QuietJmhBenchmark, whose static initializer calls BenchmarkSupport.configureQuietLogging() and initializes Logback before the fork loads anything that logs. A superclass is initialized before its subclass, so the hook holds however a benchmark orders its own static fields, and it does not depend on the JMH command line: a -jvmArgsAppend given for another reason replaces a jvmArgsAppend declared in @fork. The manual harness's opt-out, -Dgraphcompose.benchmark.logging=debug, works the same through -jvmArgsAppend. A logback.xml in the module's resources would have been simpler, but the manual harness's opt-out relies on Logback finding no configuration at all. JmhQuietLoggingGuardTest reads META-INF/BenchmarkList and every @State class of the package, initializes each in a class loader of its own and asks that loader's SLF4J whether the engine logs at DEBUG, so a benchmark added later is checked without being named.
The guard also follows the @State parameters of the benchmarks' @benchmark, @setup and @teardown methods, so a state class outside the jmh package is checked too. The CHANGELOG claims an allocation drop only where it exceeds the run's error, and ColdStart's javadoc records that Logback starts outside the shot.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The JMH layer measured the engine with its DEBUG logging switched on. Only the manual harness applies
logback-benchmark.xml(BenchmarkSupport.configureQuietLogging()); the classes undercom.demcha.compose.jmhnever called it, andbenchmarks.jarcarries nologback.xml, so every forked JVM fell back to Logback's default configuration — root at DEBUG, to the console.Measured on
develop(6ec0d7474),-prof gc, the benchmarks' own fork counts:CanonicalRenderJmhBenchmark -bm avgt(1 fork)DocxExportJmhBenchmark.docx, 4 shapes (1 fork each)ColdStartJmhBenchmark, 3 benchmarks (10 forks each)What changed
QuietJmhBenchmark(new,com.demcha.compose.jmh) — abstract base whose static initializer callsBenchmarkSupport.configureQuietLogging()and then initializes Logback (LoggerFactory.getILoggerFactory()), so Logback's start-up is outside every measured region. All 14 JMH benchmarks extend it.@Fork(jvmArgsAppend = "-Dlogback.configurationFile=…"): JMH 1.37 takes a command-line-jvmArgsAppendinstead of the annotation's (Runner:options.getJvmArgsAppend().orElse(benchmark.getJvmArgsAppend()…)), so a run passing-Xmxthat way would get the logging back without a sign. A superclass is initialized before its subclass (JLS 12.4.2) and before any@Setup, so the hook holds whatever JVM arguments the run appends, short of the opt-outs below, and however a benchmark orders its own static fields.logback.xmlin the module's resources: the manual harness's-Dgraphcompose.benchmark.logging=debugworks by leaving Logback with no configuration to find; alogback.xmlwould silence it.-jvmArgsAppend:-Dgraphcompose.benchmark.logging=debugkeeps the engine's logging, and an explicit-Dlogback.configurationFilewins.BenchmarkSupportbecomespublic(withconfigureQuietLogging(), now documented) so thejmhpackage can call it. Its behaviour is unchanged; the manual harness andab-benchcall it as before. The module is not deployed and not in the knowledge pack.JmhQuietLoggingGuardTest(new) — readsMETA-INF/BenchmarkList, the list the JMH runner reads, plus the@Stateclasses the benchmarks'@Benchmark/@Setup/@TearDownmethods take (in any package, followed through the states' own fixture methods) and every@Stateclass compiled into the package, so a benchmark or state class added later is checked without being named. Each class is initialized in a fresh class loader over the test classpath and that loader's SLF4J is asked whethercom.demcha.composelogs at DEBUG. Two more cases keep the guard honest: with nothing initialized the classpath is loud (alogback.xmlarriving on it would otherwise make every class pass), and thedebugopt-out still logs.benchmarks/README.md,docs/operations/benchmarks.mdand the CHANGELOG say how the JMH layer logs and how to opt out. JMH results recorded before 2.5.2 — the weeklybenchmarks-jmh.ymlseries among them — are not comparable with later ones.Verification
The same runs on the jar built from this branch:
gc.alloc.rate.norm, before → afterCanonicalRenderDocxExport.docxColdStartThe allocation column is the steadier one, not a noise-free one: with one fork the per-shape error is ±1–8 %, so only CanonicalRender, ColdStart and table1000 move clearly past it. Average time moved with the logging gone (CanonicalRender 2.4 → 0.5–1.6 ms/op across two runs, ColdStart engine-simple 2373 → 1194–1265 ms), but on a machine that was not kept quiet those error bars are wide. Initializing Logback in the hook changed ColdStart allocation by ≤ 0.1 % against the hook alone.
java -jar benchmarks.jar CanonicalRenderJmhBenchmark -jvmArgsAppend "-Dgraphcompose.benchmark.logging=debug"prints DEBUG again (3 452 lines in a 1-iteration run); the same run with-jvmArgsAppend "-Xmx1g"prints none../mvnw -B -ntp test -f benchmarks/pom.xml— 47 tests, 0 failures (JmhQuietLoggingGuardTest3).@Stateclass of the package not inBenchmarkListnot extending it; a@Stateclass incom.demcha.composetaken only by a@Benchmarkmethod not extending it; one taken only by another state's@Setupmethod; the hook emptied; the hook moved to an instance initializer; alogback.xmlon the test classpath; thedebugopt-out removed../mvnw -B -ntp clean verifyof the CI reactor (core, render-pdf/docx/pptx, templates, testing, qa, coverage), the JDK 17 knowledge checks, core javadoc, install and the examples tests on228ed3028— all pass (reactor 1926 tests, examples 93, 0 failures). Thebenchmarksmodule is outside that reactor; CI'sPerformance Smoke Checkruns its tests.Lane: build / benchmark tooling. No library code, no public API, no knowledge-pack change.