Skip to content

refactor(core): use bumpalo for compiler allocations - #6

Closed
OpportunityLiu wants to merge 1 commit into
mainfrom
agent/bumpalo-compiler-allocator
Closed

refactor(core): use bumpalo for compiler allocations#6
OpportunityLiu wants to merge 1 commit into
mainfrom
agent/bumpalo-compiler-allocator

Conversation

@OpportunityLiu

Copy link
Copy Markdown
Member

Summary

  • allocate parser AST nodes from one bumpalo::Bump arena per compilation
  • thread the arena through parser state and keep Monaco's persistent AST in a resettable arena
  • remove the mimalloc feature and dependency from core, N-API, Python, and the lockfile
  • keep formatter and emitter support for arena-backed AST nodes

Why

The compiler creates many small, short-lived AST allocations. The system allocator was noticeably slower than the previous mimalloc-enabled benchmark. Grouping those nodes in a compilation-scoped bump arena reduces allocation and teardown overhead without replacing the process-wide allocator.

Performance

Measured with crates/core/benches/compile.rs on examples/41_fib.mira, using the system allocator in both cases (--min-time 2 --sample-count 100):

Version Median
Before 45.69 µs
After 39.69 µs

This is about a 13.1% improvement over the system-allocator baseline.

API impact

Compiler::parse now accepts the arena that owns returned AST nodes. AST-owned box fields use parser::AstBox, and AST types no longer implement Clone where arena-backed ownership makes an implicit allocator unavailable.

Validation

  • cargo fmt --all -- --check
  • cargo check --workspace
  • cargo test --workspace
  • cargo bench -p mira-core --bench main -- compile --min-time 2 --sample-count 100
  • pnpm -r --filter "!@mirascript/website" run build
  • pnpm -r run test

@codacy-production

codacy-production Bot commented Aug 12, 2026

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 high

Alerts:
⚠ 1 issue (≤ 0 issues of at least minor severity)

Results:
1 new issue

Category Results
Security 1 high

View in Codacy

🟢 Metrics 0 complexity · 4 duplication

Metric Results
Complexity 0
Duplication 4

View in Codacy

🟢 Coverage ∅ diff coverage · +0.10% coverage variation

Metric Results
Coverage variation +0.10% coverage variation (-1.00%)
Diff coverage diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (08a978d) 14034 13570 96.69%
Head commit (b264b8c) 24176 (+10142) 23401 (+9831) 96.79% (+0.10%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#6) 0 0 ∅ (not applicable)

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@OpportunityLiu
OpportunityLiu deleted the agent/bumpalo-compiler-allocator branch August 12, 2026 05:27
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