Skip to content

Optimize test run time with autoresearch - #357

Open
jhugman wants to merge 6 commits into
mainfrom
jhugman/testing/optimize
Open

Optimize test run time with autoresearch#357
jhugman wants to merge 6 commits into
mainfrom
jhugman/testing/optimize

Conversation

@jhugman

@jhugman jhugman commented Mar 20, 2026

Copy link
Copy Markdown
Owner

Fixture test cold starts dropped from ~24min to ~20min (JSI) and ~37min to ~18min (WASM). Warm runs take 1-2min. Changing a template and re-running cargo test now works without manual steps.

How

The test infrastructure gained three things: caching, parallelism, and correct change detection.

Caching. A three-layer content-hash cache sits between source changes and rebuilds. The codegen layer hashes the cdylib and ubrn binary mtime — if neither changed, binding generation is skipped. A write-if-changed sync preserves file mtimes so downstream tools (ninja, cargo, tsc) see no change. A build-level stamp hashes the generated output and skips compilation when content is identical. Each layer short-circuits independently.

Parallelism. JSI C++ and TypeScript compilation now run concurrently. WASM fixture builds share a single cargo target directory so dependencies compile once. Cargo's --jobs flag is capped at num_cpus/3 to prevent thrashing when nextest runs multiple builds.

Change detection. ensure_ubrn_binary() always invokes cargo build (a 1-2s no-op when nothing changed). This replaced a stale-binary guard that silently skipped rebuilds after template edits.

What changed, file by file

  • ubrn_fixture_testing/src/lib.rs — Caching utilities (content hashing, cache stamps, write-if-changed sync), shared target dir management, always-rebuild ubrn binary.
  • ubrn_fixture_testing/src/jsi.rs — Codegen caching, parallel C++/TS compilation with separate cache stamps, cmake configure caching.
  • ubrn_fixture_testing/src/wasm.rs — Codegen caching, shared CARGO_TARGET_DIR, --jobs tuning.
  • ubrn_fixture_testing/src/typescript.rs — Esbuild replaces Metro for bundling.
  • ubrn_fixture_testing/src/metadata.rs — Path derivation from CARGO_TARGET_TMPDIR replaces cargo metadata.
  • cpp/hermes-rust-extension/CMakeLists.txt — Precompiled headers for JSI, -O0 for test glue.
  • cpp/test-harness/timers.js.inc — Steady clock for timer deadlines.

Verification

Every optimization was checked three ways: a warm run (caches hold), a cache-bust (modifying a generated file triggers the right rebuild), and a full dev cycle (edit a template, rebuild the codegen binary, re-run tests — the whole chain invalidates and rebuilds correctly).

@jhugman jhugman changed the title Use autoresearch to optimize test runtime Optimize test run time with autoresearch Mar 20, 2026
@jhugman
jhugman force-pushed the jhugman/testing/optimize branch 3 times, most recently from e111470 to b975d0b Compare March 20, 2026 21:59
jhugman added 3 commits March 21, 2026 18:29
…TMPDIR

Replace Metro bundler with esbuild for TypeScript test bundles. Remove
cargo_metadata dependency and derive target directory and fixture paths
directly from CARGO_TARGET_TMPDIR. Add shared caching and file-sync
utilities to lib.rs.
@jhugman
jhugman force-pushed the jhugman/testing/optimize branch from b975d0b to 7d60149 Compare March 21, 2026 18:48
jhugman added 3 commits March 21, 2026 18:50
…iled headers

- Cache codegen output (keyed on cdylib hash + ubrn binary mtime)
- Run C++ and TypeScript compilation in parallel via std::thread::scope
- Cache cmake configure step (skip when inputs unchanged)
- Add precompiled headers for jsi/jsi.h and jsi/jsi-inl.h
- Use -O0 for test C++ extension builds
- Share a single CARGO_TARGET_DIR across all wasm fixture builds
- Cache codegen output (same pattern as JSI)
- Limit cargo --jobs to max(1, num_cpus/3) to avoid CPU oversubscription
Replace cargo test with cargo nextest run across all CI jobs. Nextest
runs each test in its own process with better parallelism and output.
@jhugman
jhugman force-pushed the jhugman/testing/optimize branch from 7d60149 to 75f173c Compare March 21, 2026 18:50
@jhugman
jhugman requested review from Johennes and zzorba and removed request for Johennes March 23, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants