Skip to content

Simplify bump allocator for single-threaded PVM#11

Merged
pgherveou merged 1 commit intomainfrom
pg/bump-allocator-simplify
Feb 25, 2026
Merged

Simplify bump allocator for single-threaded PVM#11
pgherveou merged 1 commit intomainfrom
pg/bump-allocator-simplify

Conversation

@pgherveou
Copy link
Copy Markdown
Collaborator

Summary

  • Replace AtomicUsize + CAS loop with Cell<usize> in BumpAllocator — PVM contracts are single-threaded so atomics are unnecessary overhead
  • Panic on OOM instead of returning null pointer to surface allocation bugs early
  • Add alloc_zeroed shortcut that delegates to alloc since the heap is always zero-initialized
  • Add regenerate-reports.sh script for automated benchmark report generation
  • Regenerate encoding benchmark report with fresh numbers

Test plan

  • cargo test -p pvm-bump-allocator — unit tests updated to expect panics on OOM
  • cargo clippy --workspace --all-targets --all-features
  • CI passes

Replace AtomicUsize + compare_exchange loop with Cell<usize> since PVM
contracts are single-threaded. Panic on OOM instead of returning null
to fail fast and surface allocation bugs early.

Also add alloc_zeroed shortcut (heap is always zero-initialized),
regenerate encoding benchmark report, and add regenerate-reports.sh
script for automating benchmark report generation.
@github-actions
Copy link
Copy Markdown

Benchmark Size Comparison (vs main)

Artifact Baseline Current Delta Status
fibonacci_builder-dsl.debug.polkavm 36592 36592 +0.00% OK
fibonacci_builder-dsl.release.polkavm 1194 1194 +0.00% OK
fibonacci_no-alloc.debug.polkavm 35834 35834 +0.00% OK
fibonacci_no-alloc.release.polkavm 469 469 +0.00% OK
fibonacci_with-alloc.debug.polkavm 47358 45094 -4.78% OK
fibonacci_with-alloc.release.polkavm 584 448 -23.29% OK
multi_builder-dsl.debug.polkavm 53691 53691 +0.00% OK
multi_builder-dsl.release.polkavm 3568 3568 +0.00% OK
multi_no-alloc.debug.polkavm 55550 55550 +0.00% OK
multi_no-alloc.release.polkavm 3419 3419 +0.00% OK
multi_with-alloc.debug.polkavm 66896 64626 -3.39% OK
multi_with-alloc.release.polkavm 3700 3864 +4.43% OK
mytoken_builder-dsl.debug.polkavm 49965 49965 +0.00% OK
mytoken_builder-dsl.release.polkavm 4097 4097 +0.00% OK
mytoken_no-alloc.debug.polkavm 51973 51973 +0.00% OK
mytoken_no-alloc.release.polkavm 3751 3751 +0.00% OK
mytoken_with-alloc.debug.polkavm 65115 62849 -3.48% OK
mytoken_with-alloc.release.polkavm 4378 4301 -1.76% OK
---------------------------------------------------- ------------ ------------ ---------- --------
Total 488134 481285 -1.40%

OK: All artifacts within 5% regression threshold

Run 22391459972 | 580082a | 2026-02-25 10:15 UTC

@pgherveou pgherveou merged commit ab2cbbd into main Feb 25, 2026
4 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.

1 participant