Skip to content

Skip fresh auto optimized archive rebuilds#4928

Merged
proggeramlug merged 1 commit into
PerryTS:mainfrom
andrewtdiz:codex/perry-small-native-gap-20260610
Jun 19, 2026
Merged

Skip fresh auto optimized archive rebuilds#4928
proggeramlug merged 1 commit into
PerryTS:mainfrom
andrewtdiz:codex/perry-small-native-gap-20260610

Conversation

@andrewtdiz

@andrewtdiz andrewtdiz commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • skip the auto-optimized runtime/stdlib Cargo invocation when hash-keyed archives are already fresh
  • write and require a profile stamp so old archives or different feature profiles stay conservative
  • add optimized-lib freshness/no-Cargo tests plus object-cache verification coverage

Investigation

The remaining small native source-change latency was not object-cache churn. In the dep-wide-100k shape, a one-module edit should invalidate one generated TS module, reuse the other native objects, and relink. The expensive extra work was in build_optimized_libs: every build-cache miss still spawned cargo build --release -p perry-runtime -p perry-stdlib ... for the hash-keyed auto runtime/stdlib target, even when the static archives were already present and source inputs were unchanged.

This PR keeps the first run conservative. After a successful auto build writes .perry-auto-build.stamp, the next build-cache-miss source edit can reuse fresh archives without spawning Cargo. The freshness check requires:

  • matching auto-profile stamp (target, triple, feature set, shared-tokio crates)
  • existing runtime and stdlib archives
  • archives newer than Cargo.toml, Cargo.lock, perry-runtime, perry-stdlib, and any shared-tokio wrapper source dirs
  • no LLVM bitcode request

Verification

  • cargo fmt --all -- --check passed
  • cargo test -p perry build_optimized_libs_reuses_fresh_auto_archives_without_cargo -- --nocapture passed: 1 passed, 0 failed
  • cargo test -p perry optimized_libs -- --nocapture passed: 12 passed, 0 failed
  • cargo test -p perry object_cache_tests -- --nocapture passed: 27 passed, 0 failed
  • cargo build -p perry --release passed: finished release profile in 2m 03s
  • target/release/perry --version -> perry 0.5.1154

Scaled native proof

After the real host auto archives existed, the first patched compile stamped them. Then I changed one source module and reran compile with PATH=/usr/bin:/bin:/usr/sbin:/sbin, where cargo is unavailable but cc/link tools are still available. The second build succeeded, which proves the production path did not spawn Cargo.

Command shape:

/usr/bin/time -lp target/release/perry compile --format json work/scaled-native/src/main.ts -o work/scaled-native/app
# edit gen_0.ts
PATH=/usr/bin:/bin:/usr/sbin:/sbin /usr/bin/time -lp target/release/perry compile --format json work/scaled-native/src/main.ts -o work/scaled-native/app

Results:

  • first compile: 1.28s real, output 42, checksum 084c799cd551dd1d8d5c5f9a5d593b2e931f5e36122ee5c793c1d08a19839cc0
  • second source edit: 0.40s real, output 43, checksum 0e55092af0746630c98d1b2e0d960617c33f8ea7b55739fd18cb7cd5342a28ca
  • second counters: native_modules=3, build_cache.hit=false (miss_reason=env from the deliberate PATH change), codegen_cache.hits=2, misses=1, stores=1, object_cache_paths_reused=2, object_cache_paths_stored=1, link_cache.linked=true, object_fingerprints_used=3, object_files_hashed=0, external_inputs_hashed=1
  • stamp written: target/perry-auto-8981e03852ab7578/.perry-auto-build.stamp with key=crypto|true|host|wasm=false and features=perry-runtime/full,perry-stdlib/crypto

100k benchmark status

Baseline from the latest report: dep-wide-100k native small_change Rust 2.26s vs Perry 2.98s median; no-op already fixed at Rust 0.36s vs Perry 0.12s.

I generated the dep-wide-100k repro and attempted the full native small-change run, but the run was initially consumed by first-time auto runtime/stdlib archive seeding in target/perry-auto-8981e03852ab7578. Per the lane supervisor guidance, I stopped waiting on that path and switched to the focused scaled proof above. The full dep-wide-100k after wall-clock should be rerun from a seeded archive state.

Summary by CodeRabbit

  • Chores
    • Refactored build orchestration with intelligent caching mechanisms to minimize unnecessary recompilation of standard libraries, improving build performance.
    • Expanded test coverage for build cache validation logic, including freshness detection and archive reuse scenarios.
    • Updated build configuration thresholds to support ongoing development needs.

@proggeramlug proggeramlug marked this pull request as ready for review June 11, 2026 11:16
@proggeramlug proggeramlug force-pushed the codex/perry-small-native-gap-20260610 branch from 806aad8 to a0630c1 Compare June 12, 2026 11:09
@proggeramlug

Copy link
Copy Markdown
Contributor

Heads-up after rebasing this onto current main: cargo-test fails in this PR's own area — 4 commands::compile::optimized_libs tests (build_optimized_libs_reuses_fresh_auto_archives_without_cargo, forced_well_known_env_extends_iteration_set, no_auto_builds_missing_well_known_archive_from_workspace_source, no_auto_still_resolves_prebuilt_well_known_archives). Most likely a semantic conflict with #5013 (auto-optimize runtime cache is now version-keyed, merged 2026-06-11), which changed the archive resolution this PR's reuse logic asserts against. Main's other CI reds are fixed as of #5033, so these 4 are the only blockers — needs a rework against the version-keyed cache.

@proggeramlug proggeramlug force-pushed the codex/perry-small-native-gap-20260610 branch from a0630c1 to bcc873b Compare June 18, 2026 07:24
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 097deb22-3df7-4bd3-8bc0-17e54a200c20

📥 Commits

Reviewing files that changed from the base of the PR and between bcc873b and 4c58a91.

📒 Files selected for processing (2)
  • crates/perry/src/commands/compile/optimized_libs.rs
  • scripts/check_file_size.sh
🚧 Files skipped from review as they are similar to previous changes (2)
  • scripts/check_file_size.sh
  • crates/perry/src/commands/compile/optimized_libs.rs

📝 Walkthrough

Walkthrough

Introduces a stamp-and-mtime freshness cache for libperry_runtime.a and libperry_stdlib.a in build_optimized_libs. New private helpers compute a cache key, compare archive/source modification times against a stored stamp file, and fast-path return when archives are current. On successful rebuild, the stamp is written. Unit tests cover fresh, stale, and nested-directory cases. check_file_size.sh is updated to allow the now-larger file.

Changes

Optimized Libs Freshness Cache

Layer / File(s) Summary
Freshness cache helpers and imports
crates/perry/src/commands/compile/optimized_libs.rs
Adds std::fs and SystemTime imports; introduces auto_optimized_archives_are_fresh, auto_optimized_cache_key, auto_optimized_cross_features, auto_optimized_build_stamp, input_newer_than, file_modified, and resolve_auto_well_known_libs as private helpers implementing the stamp-and-mtime cache.
Wiring freshness probe and stamp write into build_optimized_libs
crates/perry/src/commands/compile/optimized_libs.rs
Replaces inline cache-key construction with auto_optimized_cache_key, derives cross_features via the new helper, moves lock acquisition earlier, calls auto_optimized_archives_are_fresh for an early fast-path return, evaluates bitcode_requested once and reuses it, and writes .perry-auto-build.stamp after a successful cargo build.
Unit tests and CI file-size allowlist
crates/perry/src/commands/compile/optimized_libs.rs, scripts/check_file_size.sh
Adds unit tests covering fresh-archive reuse, stale detection on runtime source change, and nested target directory exclusion; exempts optimized_libs.rs from the CI LOC gate.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐇 A stamp in the dirt, a trail through the source,
No need to rebuild if fresh be the course!
The archives are checked, the mtime compared,
And if cargo need not run — the bunny is spared.
Nested target dirs? Skipped with a hop!
Fast-path returns where the rebuild would stop. 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main objective: skipping auto-optimized archive rebuilds when they are fresh and already present.
Description check ✅ Passed The pull request description is comprehensive and well-structured, covering summary, investigation, verification, and benchmark results with substantial detail.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@proggeramlug proggeramlug force-pushed the codex/perry-small-native-gap-20260610 branch from bcc873b to 4c58a91 Compare June 18, 2026 08:51
@proggeramlug proggeramlug merged commit bbd90a9 into PerryTS:main Jun 19, 2026
15 checks passed
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