Repository navigation
perf: shared benchmark harness and variant switch - #2149
Merged
Merged
Conversation
-PbenchVariants (CMake NS_BENCH_VARIANTS, off by default) makes the runtime read debug.ns.benchvariant once when the library loads. C++ reads it through BenchVariant() and JS through the read-only __benchVariant global, so one benchmark APK can carry every label of an A/B. The runtime logs NS_BENCH_VARIANT=<n> at startup so a harness can reject a launch that ran the wrong variant. Without the option BenchVariant() is a constant 0, nothing reads the property and there is no JS global. The runtime's ccache switch also accepts -PuseCcache and NS_USE_CCACHE=1.
Every measureJs and measureCallback row now logs "ops": the operations it ran in the launch, warm-up and reference calls included. A counter run at two scales divided by the ops difference gives counts per operation without hard-coding each row's iteration formula.
build.sh builds the release benchmark APK (optionally with the run-time variant switch, ccache shared across checkouts, and a temporary <profileable> manifest entry). run.sh runs rotated A/B rounds on one device under a mkdir lock: one install, speed compile and discarded launch per APK per round, then a relaunch per label and filter group, checking the variant the runtime reports. table.py prints within-round ratios against an anchor, with the A/A range and bimodality flags. stat.sh and statsum.py count instructions and cycles per operation on the JS thread from two-scale simpleperf stat runs.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
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.
Description
This adds shared tooling for A/B performance experiments on the runtime, so an experiment no longer starts by copying and patching session scripts.
Run-time variant switch (
feat(runtime): run-time variant switch for benchmark builds)-PbenchVariantssets the CMake optionNS_BENCH_VARIANTS(off by default). With it, the runtime readsdebug.ns.benchvariantonce, inJNI_OnLoad.tns::BenchVariant()(BenchVariant.h), and JS through a read-only__benchVariantglobal. An experiment puts its alternatives behindif (BenchVariant() == N)in a local, bench-only commit, and one APK then covers every label.NS_BENCH_VARIANT=<n>at startup. The harness rejects a launch that ran a different variant, and aborts on an APK that reports none.BenchVariant()isconstexpr 0: the branches fold away, nothing reads the property, and there is no global. Nothing that ships passes the flag; the root build's packaging tasks don't forward it.-PuseCcacheandNS_USE_CCACHE=1, next to the existing-PuseCCache. The CMake side (RULE_LAUNCH_COMPILE) and CI's use are unchanged.opsin the JNI benchmark lines (test(bench): ...)measureJsandmeasureCallbackrows now report how many operations they ran in the launch, warm-up and reference calls included.opsdifference, gives counts per operation without hard-coding each row's iteration formula.tools/perf(build(perf): ...): bash and python3, no new dependencies. Usage is intools/perf/README.md.build.shbuilds the release,-Poptimizedarm64 test app. Options:--variantsfor the run-time variant switch.--ccachefor a dedicated, size-capped cache.CCACHE_BASEDIRis the checkout andCCACHE_NOHASHDIR=1, so worktrees share entries.--profileableadds<profileable android:shell="true"/>for one build and restores the manifest afterwards.It records the commit, the flags, the
.sohash, the wall time and the ccache hits.run.shruns rounds on one device:mkdirlock per round and cleans up only while it holds it.emulator-5554by default), and it refuses to mix devices in one output directory.table.pyprints medians and within-round ratios to an anchor, as median [min-max]. With--aaand three or more rounds, it marks each range as inside (=) or outside (*) the A/A range, and it flags bimodal labels (B).--mdprints Markdown for PR bodies.stat.sh+statsum.pyrun two-scalesimpleperf stat(instructions:u,cpu-cycles:u) on the JS thread, and report counts per op with A/A deltas.The README covers:
--no-discard, simpleperf / API level (stat needs API 29+), thermal.Measurements
ccache (arm64
-Poptimized --variants, wholebuild.shwall time, host load about 8):libNativeScript.soOne configuration takes about 25 MB of cache. A ccache build is not byte-identical to a non-ccache build: the base-dir rewrite makes
__FILE__relative (../../../../src/main/cpp/...instead of the absolute path). So both sides of a comparison should use the same setting.Round time (Galaxy S20 FE, Android 13; 4 labels × 3 filter groups = 12 measured launches per round):
--variantsAPK,run.sh(2-round smoke)The smoke's rows were shorter, so compare the overhead column. For the earlier experiment's row mix, the saving is about 40 s of ~200 s per round, plus N-1 fewer builds. Those builds were already 10-37 s each, because the labels differed only in JS. Lock waits between rounds dominated wall time in both runs (10-19 minutes with other sessions on the same phone), which is what a second device would relieve.
Smoke A/B (2 rounds;
base/base2= variant 0,v1= an emptyasm volatile("")branch inPrepareV8Runtime,v2= a 50-iteration spin at the top ofCallJavaMethodas a positive control; neither variant is in this PR):v2adds about 85-95 ns to every JS → Java method call and nothing to field access, which takes another path.callback.noArgs()is bimodal per launch on this phone (about 415 or about 1230 ns), as seen before. Two rounds cannot separate that fromv1/v2, andtable.pyflags it once there are four or more launches.stat.shcheck (same APK, made profileable, one pass, 2 min 11 s under one lock hold; per op on the JS thread, scales 4 and 20):The A/A deltas stay under one instruction per op. The positive control shows up only on the row whose path it changes.
Does your commit message include the wording below to reference a specific issue in this repo?
No.
Related Pull Requests
None.
Does your pull request have unit tests?
No new specs: the variant switch is off by default, and
tools/perfis development tooling.opswas checked by the two-scale stat run.