Skip to content

benchmark for arena2 vs boa gc#35

Merged
nekevss merged 1 commit intoboa-dev:mainfrom
shruti2522:bench-arena2
Mar 10, 2026
Merged

benchmark for arena2 vs boa gc#35
nekevss merged 1 commit intoboa-dev:mainfrom
shruti2522:bench-arena2

Conversation

@shruti2522
Copy link
Contributor

@shruti2522 shruti2522 commented Mar 6, 2026

fix #29

  • Implemented MarkSweepGarbageCollector with arena2 in mark_sweep_arena2
  • added the benchmark arena2_vs_boa_gc, documented the results in notes
  • fixed some errors occuring in mark_sweep tests

TODO once approved : plug this implementation into boa

bench results:

arena2 is much faster for simple allocations and collection sweeps, about 2x fast. In mixed tests and heavy memory tests, they perform about the same

@shruti2522 shruti2522 changed the title benchmark for arena2 vs boa gc benchmark for arena2 vs boa gc (WIP) Mar 6, 2026
@shruti2522 shruti2522 force-pushed the bench-arena2 branch 2 times, most recently from ccff1dd to cc7df09 Compare March 6, 2026 13:00
@shruti2522 shruti2522 changed the title benchmark for arena2 vs boa gc (WIP) benchmark for arena2 vs boa gc Mar 6, 2026
@shruti2522 shruti2522 marked this pull request as ready for review March 6, 2026 13:07
Copy link
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

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

Hmmmm, for the sake of quick iteration, we should split these into two modules, but can you attempt to minimize the duplication here, thinking specifically about the tracing and cell module.

This would mean splitting off the pointers, the internals, and the collector impl into versioned modules. But then we lessen the duplication.

We will also need to eventually think about a way to reuse some of this code maybe behind a trait. But let's leave that for later and focus on minimizing the duplication while having two implementations.

// SAFETY: `ArenaHeapItem` is `repr(transparent)`, use addr_of_mut! to avoid
// creating a &mut reference during trace
let raw: *mut ArenaHeapItem<GcBox<NonTraceable>> = self.as_heap_ptr().as_ptr();
unsafe { NonNull::new_unchecked(core::ptr::addr_of_mut!((*raw).0)) }
Copy link
Member

Choose a reason for hiding this comment

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

use &raw mut instead per the docs

let raw: *mut ArenaHeapItem<GcBox<NonTraceable>> = self.as_heap_ptr().as_ptr();
// SAFETY: `raw` is non-null because it comes from `as_heap_ptr()`
// `ArenaHeapItem` is `#[repr(transparent)]` so it shares the same address as field 0
unsafe { NonNull::new_unchecked(core::ptr::addr_of_mut!((*raw).0)) }
Copy link
Member

Choose a reason for hiding this comment

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

use &raw mut instead

pub(crate) type ErasedEphemeron = core::ptr::NonNull<
ArenaHeapItem<
Ephemeron<
crate::collectors::mark_sweep_arena2::internals::NonTraceable,
Copy link
Member

Choose a reason for hiding this comment

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

nit: weird formatting

Maybe just import NonTraceable directly and don't indent this.

Copy link
Member

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?

Copy link
Contributor Author

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.rs and gc_header.rs now just re-export the mark_sweep ones directly since they share the exact same types. Also added a comment about the trace macros so it's clear in the future

@shruti2522 shruti2522 force-pushed the bench-arena2 branch 3 times, most recently from d0686d1 to 71e2c09 Compare March 7, 2026 13:46
@nekevss
Copy link
Member

nekevss commented Mar 9, 2026

Needs rebase

@shruti2522 shruti2522 force-pushed the bench-arena2 branch 2 times, most recently from 277e528 to 11dc1eb Compare March 9, 2026 02:10
@shruti2522 shruti2522 marked this pull request as draft March 9, 2026 02:12
@shruti2522 shruti2522 marked this pull request as ready for review March 9, 2026 02:41
@shruti2522 shruti2522 marked this pull request as draft March 9, 2026 02:43
@shruti2522 shruti2522 force-pushed the bench-arena2 branch 2 times, most recently from a1f40e6 to ee5a62d Compare March 9, 2026 03:15
@shruti2522 shruti2522 marked this pull request as ready for review March 9, 2026 03:21
@shruti2522
Copy link
Contributor Author

Needs rebase

done

@nekevss nekevss merged commit e6b53b0 into boa-dev:main Mar 10, 2026
2 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.

Benchmarking MarkSweepGarbageCollector in Boa with arena2

2 participants