Documentation
Experiment methodology
Nine-step controlled optimization loop, six experimental control principles, three paired protocols (48-JVM / 12-JVM), Spark profiling, and evidence boundaries.
Performance validation in MTR Memory Saver follows the closed-loop standards defined in OPTIMIZATION.md, CLIENT_EXPERIMENT.md, and SPARK_PROFILING.md—relying on frozen plans, fresh-JVM isolation, instrumentation calibration, and read-only offline replay so noise or post-hoc threshold edits never distort conclusions.
1. Nine-Step Controlled Development Loop
- Define the Problem & Unit: State the observed failure or cost, exact artifact/loader/MTR/pack identities, affected phase, and relevant units—separating allocated bytes, retained heap, admitted cache weight, OS Working Set, Private Commit, and GPU VRAM; preserve raw failures.
- Diagnose Separately: Locate repeated work with JFR, GC logs, and cache counters. Diagnostic forced GCs, heap dumps, and heavy profiling add overhead and must stay outside ordinary timing windows; never infer native memory by subtracting unrelated peaks.
- Specify a Falsifiable Hypothesis: Declare the mechanism, one primary endpoint, and regression guardrails before measuring. Change one mechanism per candidate when causal attribution matters.
- Freeze the Experiment: Lock artifacts, input hashes/order, JDK/JVM flags, warm-up/measurement windows, random seeds, repetition counts, and acceptance budgets; record power mode and background constraints. Keep heap size and scheduler equal (
-Xmxreductions are separate experiments). - Establish Correctness Independently: Run native-reference geometry/text audits, failure/retry/retirement tests, and negative controls where historical bugs fail. Correctness failures block performance acceptance.
- Measure the Declared Experiment: Launch a fresh JVM per replicate using counterbalanced AB/BA order, A/A noise controls, and matched instrumentation controls. Keep all OOMs, timeouts, and slow runs; abort and discard the run directory if inputs change.
- Decide Without Moving Thresholds: Report every paired delta and its exact confidence interval. Require A/A equivalence inside tolerance, primary endpoint pass, and all guardrails satisfied. Missing data is invalid; boundary-crossing intervals are
inconclusive—never relax budgets or extend only a favorable arm. - Validate the Actual Client: Microbenchmarks cannot substitute for packaged startup,
F3+Treloads, fixed routes, native caches, and GPU ownership. - Deliver or Archive Rejections: Archive the plan, failures, raw recordings, report, and decision; rejected experiments remain permanent records (see Stage records & hashes).
2. Six Experimental Control Principles
- Independent Replicate = Fresh JVM Process: Repeated queries, epochs, heap samples, or frames inside one JVM share JIT, cache, and GC autocorrelation and are never treated as independent samples.
- Cold Template Cloning &
fresh_jvm_warm_os_cacheScope: Every trial clones a never-launched template into a clean temporary directory, rejectsJAVA_TOOL_OPTIONSinjection, pins-Xms512M -Xmx3072M -XX:+UseG1GCand-Dspark.backgroundProfiler=false, and checks16-pack order, world snapshot, camera tolerances (<= 0.1position and angle), and minimum train displacement (>= 1). Because pre-launch checks warm OS file caches, scope is explicitly declared asfresh_jvm_warm_os_cacherather than cold-disk I/O. - AB/BA Alternation, A/A Controls & Probe-Off Calibration: Alternating
AB/BAcancels temporal drift;A/Acontrols measure baseline noise; matched instrumentation pairs quantify observer and profiler overhead. - Per-Epoch
native-invalid-modelAttribution (native-diagnostic-review.json): Official MTR4.1.0-beta.2emits oneInvalid model!line fortransparent.pngfrom its default emptyRailResource. Protocols never use regex/string log whitelists; instead they verifynative-invalid-model.jsonlthread, stack depth, caller index, and returned instance for exact1:1per-epoch attribution. Any unattributed error or OOM fails qualification. - Neutral Observer
1.0.3& Truncation-Safe Log Verification: Both arms run byte-identical neutral observer JARs. ReplacingReplaceFileWafter the1.0.1/1.0.2publisher race (publisher-race),1.0.3uses WindowsFileRenameInfoEx(REPLACE_IF_EXISTS | POSIX_SEMANTICS); offline analysis verifies PIDs, launch order, and per-prefixlatest.loglengths + SHA-256 chains. - Nonparametric Binomial Intervals & Outlier Sensitivity: Paired relative deltas follow
100 * (B / A - 1)(zero-baseline metrics like Full GC use absolute deltas), with 95% confidence intervals inverted from the exact binomial sign test without normality or bootstrap assumptions. At 6 pairs, the two-sided 95% CI spans min to max; 3 pairs lack finite two-sided bounds and remaininconclusive. When host load is suspected, client_outlier_analysis.py reports Tukey1.5 × IQRand leave-one-pair-out sensitivity alongside unfiltered medians.
3. Three Paired Experiment Protocols
| Protocol Dimension | Protocol 1: Source Lookup 48-JVM (source-experiment.json) | Protocol 2: Whole-Client 48-JVM (client-experiment.json) | Protocol 3: Practical 12-JVM Spark (client-practical-verification.json) |
|---|---|---|---|
| Goal | Isolate L1 path-first vs digest-before-lookup allocation and elapsed time | Formal client evaluation of steady private RAM, load time, steady heap, frame p99, and GC | Rapid paired gate run on NF248 with Spark steady-state stack profiling |
| Process Schedule | 48 JVMs: 6 pair blocks × 8 JVMs (A/B Plain, A/B Profile, A/A Plain, A/A Profile), seed 20261114 |
4 qualification + 48 trials: 6 pair blocks × 8 JVMs, balanced AB/BA & instrumentation, seed 20261115 |
12 JVMs: 2 Plain AB/BA + 2 Profile+Spark AB/BA + 1 Plain AA + 2 Candidate Probe-Off |
| Windows & Sampling | Default 2 warm-up + 2 measured epochs (2026-11-14 ran 1+1×2), 10 ms heap sampler |
Launch to first settled native sample after RETURN = loading; then 60 s warm-up + 180 s steady (2 s cadence, max gap 5 s) |
Same 60 s warm-up + 180 s steady; Profile adds Spark 1.10.124 (100 ms all threads 300 s); Probe-Off 300 s warm-up + 180 s steady |
| Primary Endpoint | Live-thread allocated bytes: median delta <= -10% |
Plain steady private RAM (steady_private_bytes): median delta <= -10% |
Plain steady private RAM: median delta <= -10% |
| Guardrails | Elapsed time <= +5% |
Plain load <= +5%; Plain steady heap <= +5%; Profile frame p99 <= +5%; GC total pause <= +50 ms; Full GC <= 0 |
Inherits all 6 guardrails from Protocol 2 |
| A/A & Calibration | A/A time ±15%, alloc ±5%; Profile & Plain never pooled |
A/A private/heap ±5%, load ±15%, frame p99 ±10%, GC ±50 ms/Full GC 0; JFR overhead ±10%/±15%; requires neutral_probe_off_calibration |
AA private/heap ±5%, load ±15%; JFR+Spark overhead ±10%/±15%; Observer+idle Spark vs Probe-Off private ±10% |
4. Evidence Scope & Metric Interpretation
4.1 What Each Evidence Class Can and Cannot Establish
| Evidence Class | What It Establishes | What Cannot Be Extrapolated |
|---|---|---|
| Static Audits & Java Unit Tests | Data-structure bounds, lock ordering, failure paths, UTF-8/UTF-16 byte parity | Runtime Mixin application, whole-client memory, or FPS |
Microbenchmarks & 64 MiB Negative Controls |
Sub-path allocation, CPU, and OOM behavior (L1 hit, single-pass digest, streaming vs String.join) |
Full-client load duration, Full GC pauses, or steady private RAM |
| Capacity Baselines & 20-Reload Endurance | Whether full packs load, reload (F3+T), clean handles, and exit cleanly under -Xmx |
Percentage speedup or RAM savings vs baseline at equal heap |
| Controlled Paired Trials (48-JVM / 12-JVM) | Paired median delta & exact binomial CI under controlled hardware/instrumentation | Behavior on unmeasured hardware, pack catalogs, or without Probe-Off calibration |
| Targeted In-World & Collision Cache Checks | Rendering visibility and floor/door box parity on specific stations/models | Full-catalog visual fidelity, glass transparency, or 2-hour route endurance |
4.2 Correct Interpretation of Runtime Observations
| Observation | Correct Interpretation |
|---|---|
| Live-thread allocated bytes | Allocation traffic of threads still observable at endpoint; terminated threads can be missed |
| Sampled heap peak | Maximum sampled heap; brief spikes between intervals can be missed |
| Post-release Full-GC heap | Diagnostic snapshot after explicit cleanup/GC outside timed windows; not proof of zero leaks |
| JVM GC count / milliseconds | Collector counter deltas—not exact STW pause distributions or exclusively Full GC |
| JFR pause spans | Whole bounded events; avoid double-counting nested pauses or cross-phase attribution |
| Frame intervals | Render-loop pacing including VSync/FPS cap—not independent GPU presentation timestamps |
5. Executable Harnesses & Scenario Schema
5.1 Paired Source Benchmark (tools/benchmark_sources.py)
Runs in three sequential phases (plan -> run -> analyze) so the full schedule is frozen before timing; existing execution directories cannot be resumed or overwritten:
python tools/benchmark_sources.py plan `
--java-home '<Java 21 JDK>' `
--baseline '<baseline JAR>' --candidate '<candidate JAR>' `
--jobs '<jobs.json>' --policy config/source-experiment.json `
--environment-notes '<power mode, background activity and limitations>' `
--output '<new experiment directory>'
python tools/benchmark_sources.py run --plan '<experiment directory>/plan.json'
python tools/benchmark_sources.py analyze --plan '<experiment directory>/plan.json' `
--output '<new analysis.json>'
5.2 Whole-Client Template Preparation (tools/packaged_client.py prepare)
Prepares four never-launched templates (baseline/plain, baseline/profile, candidate/plain, candidate/profile) from a stopped isolated source client using --performance --controls <scenario.json>:
.venv/Scripts/python.exe tools/packaged_client.py prepare `
--source <stopped-source> --instance <fresh-baseline-plain-template> `
--companion <exact-baseline.jar> --legacy-baseline official-030-nf248 `
--observer <exact-neutral-observer.jar> --catalogue <official-native-catalogue.json> `
--world <world-name> --username <local-profile-name> --performance `
--controls <scenario.json> --heap-mib 3072 --initial-heap-mib 512 `
--jvm-arg=-XX:+UseG1GC
Expand: Complete scenario.json schema for whole-client trials
{
"schema": 1,
"scenario_name": "Name of the actual measured scene",
"expected_registration": {"declarations": 12, "distinct_ids": 11},
"world_name": "Actual direct-child world name",
"camera": {
"dimension": "minecraft:overworld",
"player": {"x": 0, "y": 64, "z": 0, "yaw": 0, "pitch": 0},
"maximum_position_error": 0.1,
"maximum_angle_error": 0.1
},
"route": {
"description": "Actual fixed route and observation point",
"route_ids": [10],
"vehicle_ids": []
},
"cache_policy": "fresh_jvm_warm_os_cache",
"observation": {
"require_world": true,
"require_unpaused": true,
"require_train": true,
"minimum_train_displacement": 1
},
"machine_context": {
"hardware": "Actual CPU, RAM and GPU context",
"windows": "Actual Windows version and build",
"power_mode": "Actual power mode and relevant tuning",
"background_workload": "Actual scheduler/background workload controls"
},
"warmup": {
"duration_seconds": 60,
"description": "Actual native and scene warm-up procedure"
}
}
6. Local Spark 1.10.124 Profiling & Offline Decoding
Windows / Minecraft 1.21.1 NeoForge diagnostics use Spark 1.10.124 (Modrinth v5qtqRQi, SHA-256 647e8a81afbe414dba1df4ba15fd06c5d32d4cb544e68828405e8e074c2e16db), injected explicitly via --measurement-mod and excluded from product releases. Always freeze -Dspark.backgroundProfiler=false across all groups.
- Sampling Cadence (
engineering-053): Windows Java sampling suffers safepoint bias; the4 msall-thread pilot caused frequent expensiveThreadDumpsafepoints. Switching to100 mswith an explicit timeout saves locally without uploading:
/sparkc profiler start --thread * --interval 100 --force-java-sampler --timeout 30 --save-to-file
- Offline Protobuf Export (No Minecraft Loaded): SparkProfileExport.java uses Spark’s public generated protobuf getters, and spark_profile_analysis.py analyzes exact thread names (e.g.,
'Render thread'). Note that Spark metadataintervalis stored in microseconds (versus milliseconds on the CLI), and sample weights are not CPU elapsed time or frame durations:
javac --release 17 -encoding UTF-8 -d .cache/spark-export tools/SparkProfileExport.java
java -cp .cache/spark-export SparkProfileExport --self-test
java -cp ".cache/spark-export;<audited-spark.jar>" SparkProfileExport <local.sparkprofile> > .cache/spark-export.json
python tools/spark_profile_analysis.py .cache/spark-export.json --thread "Render thread"
Further Reading
- Stage records & hashes: Stage 5.1–5.7 outcomes,
inconclusiveverdicts, open P1/P2 gates, and the full 64-char SHA-256 registry. - Benchmarks & validation: Player-facing summary table for
v0.4.9. - Build, CI/CD & replay: Offline cryptographic replay commands and 5-point verification checklist.