Skip to content

Commit 3a88f6a

Browse files
authored
move arena3 to mempool3 (boa-dev#32)
1 parent 0442fb6 commit 3a88f6a

File tree

19 files changed

+342
-378
lines changed

19 files changed

+342
-378
lines changed

notes/coll_alloc_supertrait/arena2_vs_arena3.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ but arena3 fits more objects into the same amount of memory
1717
arena2 is faster at every size and the gap grows as object count goes up
1818

1919
| objects | arena3 | arena2 |
20-
|---------|---------|---------|
2120
| 100 | 1.02 µs | 643 ns |
2221
| 500 | 4.15 µs | 1.83 µs |
2322
| 1000 | 8.36 µs | 2.77 µs |
@@ -34,7 +33,6 @@ header on every object. But this bench is measuring allocation time, not memory
3433
writing the header is cheap, what costs time in arena3 is the size class routing.
3534

3635
| objects | arena3 (0-byte header) | arena2 (8-byte header) |
37-
|---------|---------|---------|
3836
| 100 | 781 ns | 257 ns |
3937
| 500 | 3.56 µs | 1.08 µs |
4038
| 1000 | 7.02 µs | 2.15 µs |
@@ -91,7 +89,6 @@ the whole suite
9189
time to free all objects and reclaim dead arenas:
9290

9391
| objects | arena3 | arena2 |
94-
|---------|---------|---------|
9592
| 100 | 951 ns | 665 ns |
9693
| 500 | 2.57 µs | 2.11 µs |
9794
| 1000 | 4.65 µs | 4.97 µs |

oscars/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ harness = false
2020
required-features = ["gc_allocator"]
2121

2222
[[bench]]
23-
name = "arena2_vs_arena3"
23+
name = "arena2_vs_mempool3"
2424
harness = false
2525

2626
[features]
Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ fn bench_alloc_speed(c: &mut Criterion) {
66

77
for num_objects in [100, 500, 1000].iter() {
88
group.bench_with_input(
9-
BenchmarkId::new("arena3", num_objects),
9+
BenchmarkId::new("mempool3", num_objects),
1010
num_objects,
1111
|b, &num_objects| {
1212
b.iter(|| {
1313
let mut allocator =
14-
oscars::alloc::arena3::ArenaAllocator::default().with_arena_size(65536);
14+
oscars::alloc::mempool3::PoolAllocator::default().with_page_size(65536);
1515

1616
let mut ptrs = Vec::new();
1717
for i in 0..num_objects {
1818
let ptr = allocator.try_alloc(i).expect("allocation failed");
1919
ptrs.push(ptr);
2020
}
2121

22-
black_box((ptrs.len(), allocator.arenas_len()))
22+
black_box((ptrs.len(), allocator.pools_len()))
2323
});
2424
},
2525
);
@@ -34,6 +34,7 @@ fn bench_alloc_speed(c: &mut Criterion) {
3434

3535
let mut ptrs = Vec::new();
3636
for i in 0..num_objects {
37+
let i: usize = i;
3738
let ptr = allocator.try_alloc(i).expect("allocation failed");
3839
ptrs.push(ptr);
3940
}
@@ -59,12 +60,12 @@ fn bench_small_objects(c: &mut Criterion) {
5960

6061
for num_objects in [100, 500, 1000].iter() {
6162
group.bench_with_input(
62-
BenchmarkId::new("arena3", num_objects),
63+
BenchmarkId::new("mempool3", num_objects),
6364
num_objects,
6465
|b, &num_objects| {
6566
b.iter(|| {
6667
let mut allocator =
67-
oscars::alloc::arena3::ArenaAllocator::default().with_arena_size(32768);
68+
oscars::alloc::mempool3::PoolAllocator::default().with_page_size(32768);
6869

6970
for i in 0..num_objects {
7071
let obj = SmallObject {
@@ -74,7 +75,7 @@ fn bench_small_objects(c: &mut Criterion) {
7475
let _ = allocator.try_alloc(obj).expect("allocation failed");
7576
}
7677

77-
black_box(allocator.arenas_len())
78+
black_box(allocator.pools_len())
7879
});
7980
},
8081
);
@@ -88,6 +89,7 @@ fn bench_small_objects(c: &mut Criterion) {
8889
oscars::alloc::arena2::ArenaAllocator::default().with_arena_size(32768);
8990

9091
for i in 0..num_objects {
92+
let i: usize = i;
9193
let obj = SmallObject {
9294
_a: i as u64,
9395
_b: i as u64 * 2,
@@ -107,10 +109,10 @@ fn bench_small_objects(c: &mut Criterion) {
107109
fn bench_mixed(c: &mut Criterion) {
108110
let mut group = c.benchmark_group("3_mixed_sizes");
109111

110-
group.bench_function("arena3", |b| {
112+
group.bench_function("mempool3", |b| {
111113
b.iter(|| {
112114
let mut allocator =
113-
oscars::alloc::arena3::ArenaAllocator::default().with_arena_size(65536);
115+
oscars::alloc::mempool3::PoolAllocator::default().with_page_size(65536);
114116

115117
for _ in 0..50 {
116118
let _ = allocator.try_alloc([0u8; 16]);
@@ -119,7 +121,7 @@ fn bench_mixed(c: &mut Criterion) {
119121
let _ = allocator.try_alloc([0u8; 128]);
120122
}
121123

122-
black_box(allocator.arenas_len())
124+
black_box(allocator.pools_len())
123125
});
124126
});
125127

@@ -148,20 +150,20 @@ fn bench_density(c: &mut Criterion) {
148150

149151
const PAGE_SIZE: usize = 4096;
150152

151-
group.bench_function("arena3", |b| {
153+
group.bench_function("mempool3", |b| {
152154
b.iter(|| {
153155
let mut allocator =
154-
oscars::alloc::arena3::ArenaAllocator::default().with_arena_size(PAGE_SIZE);
156+
oscars::alloc::mempool3::PoolAllocator::default().with_page_size(PAGE_SIZE);
155157

156158
let mut count = 0;
157159
while allocator.try_alloc([0u64; 2]).is_ok() {
158160
count += 1;
159-
if allocator.arenas_len() > 1 {
161+
if allocator.pools_len() > 1 {
160162
break;
161163
}
162164
}
163165

164-
black_box((count, allocator.arenas_len()))
166+
black_box((count, allocator.pools_len()))
165167
});
166168
});
167169

@@ -189,10 +191,10 @@ fn bench_density(c: &mut Criterion) {
189191
fn bench_vec_growth(c: &mut Criterion) {
190192
let mut group = c.benchmark_group("5_vec_growth");
191193

192-
group.bench_function("arena3", |b| {
194+
group.bench_function("mempool3", |b| {
193195
b.iter(|| {
194196
let mut allocator =
195-
oscars::alloc::arena3::ArenaAllocator::default().with_arena_size(32768);
197+
oscars::alloc::mempool3::PoolAllocator::default().with_page_size(32768);
196198

197199
let mut cap = 1;
198200
while cap <= 1024 {
@@ -235,7 +237,7 @@ fn bench_vec_growth(c: &mut Criterion) {
235237
cap *= 2;
236238
}
237239

238-
black_box(allocator.arenas_len())
240+
black_box(allocator.pools_len())
239241
});
240242
});
241243

@@ -296,16 +298,16 @@ fn bench_throughput(c: &mut Criterion) {
296298
let mut group = c.benchmark_group("6_sustained_throughput");
297299
group.throughput(criterion::Throughput::Elements(10000));
298300

299-
group.bench_function("arena3", |b| {
301+
group.bench_function("mempool3", |b| {
300302
b.iter(|| {
301303
let mut allocator =
302-
oscars::alloc::arena3::ArenaAllocator::default().with_arena_size(131072);
304+
oscars::alloc::mempool3::PoolAllocator::default().with_page_size(131072);
303305

304306
for i in 0..10000 {
305307
let _ = allocator.try_alloc(i);
306308
}
307309

308-
black_box(allocator.arenas_len())
310+
black_box(allocator.pools_len())
309311
});
310312
});
311313

@@ -332,13 +334,13 @@ fn bench_dealloc_speed(c: &mut Criterion) {
332334
// using `iter_batched` ensures we only measure the deallocation phase
333335
for num_objects in [100, 500, 1000].iter() {
334336
group.bench_with_input(
335-
BenchmarkId::new("arena3", num_objects),
337+
BenchmarkId::new("mempool3", num_objects),
336338
num_objects,
337339
|b, &num_objects| {
338340
b.iter_batched(
339341
|| {
340342
let mut allocator =
341-
oscars::alloc::arena3::ArenaAllocator::default().with_arena_size(65536);
343+
oscars::alloc::mempool3::PoolAllocator::default().with_page_size(65536);
342344

343345
let mut ptrs = Vec::new();
344346
for i in 0..num_objects {
@@ -347,12 +349,14 @@ fn bench_dealloc_speed(c: &mut Criterion) {
347349
}
348350
(allocator, ptrs)
349351
},
350-
|(mut allocator, ptrs)| {
352+
|(mut allocator, ptrs): (_, _)| {
351353
for ptr in ptrs {
352-
allocator.free_slot(ptr.as_ptr().cast::<u8>());
354+
unsafe {
355+
allocator.free_slot_typed(ptr.as_ptr());
356+
}
353357
}
354-
allocator.drop_dead_arenas();
355-
black_box(allocator.arenas_len())
358+
allocator.drop_empty_pools();
359+
black_box(allocator.pools_len())
356360
},
357361
criterion::BatchSize::SmallInput,
358362
);
@@ -370,12 +374,13 @@ fn bench_dealloc_speed(c: &mut Criterion) {
370374

371375
let mut ptrs = Vec::new();
372376
for i in 0..num_objects {
377+
let i: usize = i;
373378
let ptr = allocator.try_alloc(i).expect("allocation failed");
374379
ptrs.push(ptr);
375380
}
376381
(allocator, ptrs)
377382
},
378-
|(mut allocator, ptrs)| {
383+
|(mut allocator, ptrs): (_, _)| {
379384
for ptr in ptrs {
380385
let mut heap_item_ptr = ptr.as_ptr();
381386
unsafe {

oscars/benches/oscars_vs_boa_gc.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn bench_alloc(c: &mut Criterion) {
1111
for size in [10, 100, 1000].iter() {
1212
group.bench_with_input(BenchmarkId::new("oscars", size), size, |b, &size| {
1313
let collector = MarkSweepGarbageCollector::default()
14-
.with_arena_size(65536)
14+
.with_page_size(65536)
1515
.with_heap_threshold(262144);
1616

1717
b.iter(|| {
@@ -56,7 +56,7 @@ fn bench_collection(c: &mut Criterion) {
5656
b.iter_batched(
5757
|| {
5858
let collector = MarkSweepGarbageCollector::default()
59-
.with_arena_size(65536)
59+
.with_page_size(65536)
6060
.with_heap_threshold(262144);
6161
let mut roots = Vec::new();
6262
for i in 0..num_objects {
@@ -110,7 +110,7 @@ fn bench_vec_create(c: &mut Criterion) {
110110
size,
111111
|b, &size| {
112112
let collector = MarkSweepGarbageCollector::default()
113-
.with_arena_size(65536)
113+
.with_page_size(65536)
114114
.with_heap_threshold(262144);
115115

116116
b.iter(|| {
@@ -153,7 +153,7 @@ fn bench_vec_ptrs(c: &mut Criterion) {
153153
num_elements,
154154
|b, &num_elements| {
155155
let collector = MarkSweepGarbageCollector::default()
156-
.with_arena_size(65536)
156+
.with_page_size(65536)
157157
.with_heap_threshold(262144);
158158

159159
b.iter(|| {
@@ -199,7 +199,7 @@ fn bench_mixed(c: &mut Criterion) {
199199

200200
group.bench_function("oscars", |b| {
201201
let collector = MarkSweepGarbageCollector::default()
202-
.with_arena_size(65536)
202+
.with_page_size(65536)
203203
.with_heap_threshold(131072);
204204

205205
b.iter(|| {
@@ -249,7 +249,7 @@ fn bench_pressure(c: &mut Criterion) {
249249

250250
group.bench_function("oscars", |b| {
251251
let collector = MarkSweepGarbageCollector::default()
252-
.with_arena_size(32768)
252+
.with_page_size(32768)
253253
.with_heap_threshold(65536);
254254

255255
b.iter(|| {
@@ -316,7 +316,7 @@ fn bench_deep(c: &mut Criterion) {
316316

317317
group.bench_function("oscars", |b| {
318318
let collector = MarkSweepGarbageCollector::default()
319-
.with_arena_size(131072)
319+
.with_page_size(131072)
320320
.with_heap_threshold(262144);
321321

322322
b.iter(|| {

oscars/src/alloc/arena2/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ impl From<LayoutError> for ArenaAllocError {
3737
// This may also point to a different problem which is that the arena's as they
3838
// currently exist do not have a lifetime, their lifetime is derived from the
3939
// ArenaAllocator.
40-
//
41-
// But this may all be something to work on in arena3
4240

4341
// NOTE: Vec may actually be better here over link list.
4442

0 commit comments

Comments
 (0)