Skip to content

Reduce v2 self-host memory#27366

Merged
medvednikov merged 4 commits into
masterfrom
codex/v2-reduce-selfhost-ram
Jun 6, 2026
Merged

Reduce v2 self-host memory#27366
medvednikov merged 4 commits into
masterfrom
codex/v2-reduce-selfhost-ram

Conversation

@medvednikov

@medvednikov medvednikov commented Jun 6, 2026

Copy link
Copy Markdown
Member

Summary

  • store v2 expression types sparsely and release the cache after ARM64 SSA build
  • avoid large checker fallback-var map clones and string-heavy type name comparisons
  • prune unused compiler backend modules on ARM64 before transform/SSA and release SSA/MIR/ARM64 codegen arenas once consumed

Impact

ARM64 v2 self-host peak RSS drops from ~9.25 GB to ~4.12 GB on:
./v2 --no-parallel -nocache -gc none -backend arm64 -O0 -o /tmp/v2_mem_final v2.v.

Cleanc remains heavier on this branch. Current measurement:
./v2 --no-parallel -nocache -gc none -backend cleanc -O0 -o /tmp/v2_mem_final_cleanc v2.v

  • max RSS: ~6.62 GB
  • peak memory footprint: ~12.24 GB
  • total time: ~40s, with C generation taking ~29.7s

This does not reach the <1 GB target; remaining memory is dominated by transformed AST + backend-specific generated representation overlap and should be handled by the flat-AST/direct-lowering work.

Validation

  • ../../v -gc none -cc cc -o v2 v2.v
  • ./v -gc none vlib/v2/types/checker_test.v
  • ./v -gc none vlib/v2/transformer/propagate_types_from_flat_test.v
  • ./v -gc none vlib/v2/transformer/transformer_v2_darwin_test.v
  • ./v -gc none vlib/v2/abi/abi_test.v
  • ./v -gc none vlib/v2/builder/target_os_test.v
  • cd cmd/v2 && sh test_all.sh

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0c229f3f46

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v2/builder/builder.v
Comment on lines +2464 to +2466
fn (b &Builder) should_prune_native_backend_modules(arch pref.Arch) bool {
return b.pref.single_backend || arch == .arm64
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Limit ARM64 backend pruning to compiler backend files

This makes every ARM64 native build populate skip_modules for module basenames like x64, c, v, eval, and cleanc. The SSA builder’s filter only checks b.cur_module in b.skip_modules (not the file path), so any reachable user/imported module with one of those names is dropped entirely on ARM64 even though it is not an unused compiler backend. This was previously gated by --single-backend; the new arch == .arm64 default can produce missing functions or broken output for ordinary ARM64 builds that happen to use one of these module names.

Useful? React with 👍 / 👎.

@medvednikov medvednikov merged commit a715332 into master Jun 6, 2026
62 of 83 checks passed
@medvednikov medvednikov deleted the codex/v2-reduce-selfhost-ram branch June 6, 2026 13:07
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.

1 participant