-
Notifications
You must be signed in to change notification settings - Fork 14
benchmark for arena2 vs boa gc #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # arena2 vs boa_gc benchmark results | ||
|
|
||
| Note author: shruti2522 | ||
| date: 2026-03-06 | ||
|
|
||
| This benchmark measures how the `arena2` allocator which uses a simple bump allocator with `TaggedPtr` headers for liveness compares against the standard `boa_gc` implementation | ||
|
|
||
| Ran the `arena2_vs_boa_gc` bench suite. It compares oscars' `arena2` against `boa_gc` across node allocation, collection pauses, mixed workloads, and memory pressure. | ||
|
|
||
| ## Results | ||
|
|
||
| ### gc_node_allocation | ||
|
|
||
| arena2 heavily outperforms boa_gc across all sizes. | ||
| - **10 nodes:** arena2 takes ~320 ns vs ~750 ns for boa_gc | ||
| - **100 nodes:** arena2 takes ~3.2 µs vs ~6.4 µs for boa_gc | ||
| - **1000 nodes:** arena2 takes ~27.3 µs vs ~56.2 µs for boa_gc | ||
|
|
||
| This shows that bump allocation into an arena page is consistently more than 2x faster than whatever the standard boa_gc is doing. | ||
|
|
||
| ### gc_collection_pause | ||
|
|
||
| Similar to allocations, the sweep phase in arena2 is extremely fast compared to boa_gc. | ||
| - **100 objects:** arena2 sweeps in ~3.5 µs vs ~7.3 µs for boa_gc | ||
| - **500 objects:** arena2 sweeps in ~15.2 µs vs ~32.5 µs for boa_gc | ||
| - **1000 objects:** arena2 sweeps in ~29.5 µs vs ~74.9 µs for boa_gc | ||
|
|
||
| The linear scan over the contiguous blocks in arena2 during garbage collection cuts the pause times by more than half. | ||
|
|
||
| ### mixed_workload | ||
|
|
||
| This tests repeated allocations spread around `collect()` pauses. | ||
| Both allocators performed similarly here. arena2 took ~17.8 µs and boa_gc took ~17.8 µs. So arena2's big speed advantage seems to even out when allocations and collections are mixed together. | ||
|
|
||
| ### memory_pressure | ||
|
|
||
| This tests creating and deleting many objects quickly (make 50, keep 5, collect, repeat 10 times). | ||
| both allocators are equally fast here. arena2 took ~46.0 µs and boa_gc took ~46.6 µs. The cost of throwing away whole memory pages versus single objects seems to balance out | ||
|
|
||
| ## Conclusion | ||
|
|
||
| `arena2` is much faster for simple allocations and collection sweeps, about twice as fast. In mixed tests and heavy memory tests, they perform about the same. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| use criterion::{BenchmarkId, Criterion, black_box, criterion_group, criterion_main}; | ||
| use oscars::collectors::mark_sweep_arena2::{ | ||
| Finalize, Gc as OscarsGc, MarkSweepGarbageCollector, Trace, TraceColor, | ||
| cell::GcRefCell as OscarsGcRefCell, | ||
| }; | ||
|
|
||
| use boa_gc::{Gc as BoaGc, GcRefCell as BoaGcRefCell, force_collect as boa_force_collect}; | ||
|
|
||
| fn bench_alloc(c: &mut Criterion) { | ||
| let mut group = c.benchmark_group("gc_node_allocation"); | ||
|
|
||
| for size in [10, 100, 1000].iter() { | ||
| group.bench_with_input(BenchmarkId::new("arena2", size), size, |b, &size| { | ||
| let collector = MarkSweepGarbageCollector::default() | ||
| .with_arena_size(65536) | ||
| .with_heap_threshold(262144); | ||
|
|
||
| b.iter(|| { | ||
| let mut roots = Vec::new(); | ||
| for i in 0..size { | ||
| let root = OscarsGc::new_in(OscarsGcRefCell::new(i), &collector); | ||
| roots.push(root); | ||
| } | ||
| black_box(roots.len()) | ||
| }); | ||
| }); | ||
|
|
||
| group.bench_with_input(BenchmarkId::new("boa_gc", size), size, |b, &size| { | ||
| b.iter_batched( | ||
| || { | ||
| boa_force_collect(); | ||
| }, | ||
| |()| { | ||
| let mut gcs = Vec::new(); | ||
| for i in 0..size { | ||
| let gc = BoaGc::new(BoaGcRefCell::new(i)); | ||
| gcs.push(gc); | ||
| } | ||
| black_box(gcs.len()) | ||
| }, | ||
| criterion::BatchSize::SmallInput, | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| group.finish(); | ||
| } | ||
|
|
||
| fn bench_collection(c: &mut Criterion) { | ||
| let mut group = c.benchmark_group("gc_collection_pause"); | ||
|
|
||
| for size in [100, 500, 1000].iter() { | ||
| group.bench_with_input(BenchmarkId::new("arena2", size), size, |b, &size| { | ||
| let collector = MarkSweepGarbageCollector::default() | ||
| .with_arena_size(65536) | ||
| .with_heap_threshold(262144); | ||
|
|
||
| b.iter(|| { | ||
| let mut roots = Vec::new(); | ||
| for i in 0..size { | ||
| let root = OscarsGc::new_in(OscarsGcRefCell::new(i), &collector); | ||
| roots.push(root); | ||
| } | ||
| // let half be garbage | ||
| roots.truncate(size / 2); | ||
| collector.collect(); | ||
| black_box(roots.len()) | ||
| }); | ||
| }); | ||
|
|
||
| group.bench_with_input(BenchmarkId::new("boa_gc", size), size, |b, &size| { | ||
| b.iter(|| { | ||
| let mut gcs = Vec::new(); | ||
| for i in 0..size { | ||
| let gc = BoaGc::new(BoaGcRefCell::new(i)); | ||
| gcs.push(gc); | ||
| } | ||
| gcs.truncate(size / 2); | ||
| boa_force_collect(); | ||
| black_box(gcs.len()) | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| group.finish(); | ||
| } | ||
|
|
||
| fn bench_mixed(c: &mut Criterion) { | ||
| let mut group = c.benchmark_group("mixed_workload"); | ||
|
|
||
| group.bench_function("arena2", |b| { | ||
| let collector = MarkSweepGarbageCollector::default() | ||
| .with_arena_size(65536) | ||
| .with_heap_threshold(131072); | ||
|
|
||
| b.iter(|| { | ||
| let mut roots = Vec::new(); | ||
|
|
||
| for i in 0..100 { | ||
| let root = OscarsGc::new_in(OscarsGcRefCell::new(i), &collector); | ||
| roots.push(root); | ||
| } | ||
| collector.collect(); | ||
|
|
||
| for i in 100..200 { | ||
| let root = OscarsGc::new_in(OscarsGcRefCell::new(i), &collector); | ||
| roots.push(root); | ||
| } | ||
| collector.collect(); | ||
|
|
||
| black_box(roots.len()) | ||
| }); | ||
| }); | ||
|
|
||
| group.bench_function("boa_gc", |b| { | ||
| b.iter(|| { | ||
| let mut gcs = Vec::new(); | ||
|
|
||
| for i in 0..100 { | ||
| let gc = BoaGc::new(BoaGcRefCell::new(i)); | ||
| gcs.push(gc); | ||
| } | ||
| boa_force_collect(); | ||
|
|
||
| for i in 100..200 { | ||
| let gc = BoaGc::new(BoaGcRefCell::new(i)); | ||
| gcs.push(gc); | ||
| } | ||
| boa_force_collect(); | ||
|
|
||
| black_box(gcs.len()) | ||
| }); | ||
| }); | ||
|
|
||
| group.finish(); | ||
| } | ||
|
|
||
| fn bench_pressure(c: &mut Criterion) { | ||
| let mut group = c.benchmark_group("memory_pressure"); | ||
|
|
||
| group.bench_function("arena2", |b| { | ||
| let collector = MarkSweepGarbageCollector::default() | ||
| .with_arena_size(32768) | ||
| .with_heap_threshold(65536); | ||
|
|
||
| b.iter(|| { | ||
| let mut live = Vec::new(); | ||
|
|
||
| for round in 0..10 { | ||
| for i in 0..50 { | ||
| let obj = OscarsGc::new_in(OscarsGcRefCell::new(round * 100 + i), &collector); | ||
| if i % 10 == 0 { | ||
| live.push(obj); | ||
| } | ||
| } | ||
| collector.collect(); | ||
| } | ||
|
|
||
| black_box(live.len()) | ||
| }); | ||
| }); | ||
|
|
||
| group.bench_function("boa_gc", |b| { | ||
| b.iter(|| { | ||
| let mut live = Vec::new(); | ||
|
|
||
| for round in 0..10 { | ||
| for i in 0..50 { | ||
| let obj = BoaGc::new(BoaGcRefCell::new(round * 100 + i)); | ||
| if i % 10 == 0 { | ||
| live.push(obj); | ||
| } | ||
| } | ||
| boa_force_collect(); | ||
| } | ||
|
|
||
| black_box(live.len()) | ||
| }); | ||
| }); | ||
|
|
||
| group.finish(); | ||
| } | ||
|
|
||
| criterion_group!( | ||
| benches, | ||
| bench_alloc, | ||
| bench_collection, | ||
| bench_mixed, | ||
| bench_pressure, | ||
| ); | ||
|
|
||
| criterion_main!(benches); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Mark sweep collector | ||
|
|
||
| This is a basic mark-sweep collector using an underlying arena2 allocator. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| //! A garbage collected cell implementation | ||
|
|
||
| pub use crate::collectors::mark_sweep::cell::{ | ||
| BorrowError, BorrowMutError, GcRef, GcRefCell, GcRefMut, | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs to be copied again. Is there a reason the other cell intrinsics can't be shared between the two approaches here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed duplication in
cell.rs,trace.rsandgc_header.rsnow just re-export themark_sweepones directly since they share the exact same types. Also added a comment about the trace macros so it's clear in the future