-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(allocator): Fix allocator & add benchmark (#9234)
**Related issue:** - This PR is a part of #9230.
- Loading branch information
Showing
9 changed files
with
226 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -330,6 +330,7 @@ jobs: | |
tool: [email protected] | ||
|
||
- name: Check compilation | ||
if: matrix.settings.os == 'ubuntu-latest' | ||
run: | | ||
./scripts/github/run-cargo-hack.sh ${{ matrix.settings.crate }} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,92 @@ | ||
extern crate swc_malloc; | ||
|
||
use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion}; | ||
use swc_allocator::{FastAlloc, MemorySpace}; | ||
|
||
fn bench_alloc(c: &mut Criterion) { | ||
fn direct_alloc_std(b: &mut Bencher, times: usize) { | ||
b.iter(|| { | ||
let mut buf = std::vec::Vec::new(); | ||
for i in 0..times { | ||
let item: std::boxed::Box<usize> = black_box(std::boxed::Box::new(black_box(i))); | ||
buf.push(item); | ||
} | ||
}) | ||
} | ||
|
||
fn direct_alloc_no_scope(b: &mut Bencher, times: usize) { | ||
b.iter(|| { | ||
let mut vec = swc_allocator::vec::Vec::new(); | ||
for i in 0..times { | ||
let item: swc_allocator::boxed::Box<usize> = | ||
black_box(swc_allocator::boxed::Box::new(black_box(i))); | ||
vec.push(item); | ||
} | ||
}) | ||
} | ||
|
||
fn fast_alloc_no_scope(b: &mut Bencher, times: usize) { | ||
b.iter(|| { | ||
let allocator = FastAlloc::default(); | ||
|
||
let mut vec = allocator.vec(); | ||
for i in 0..times { | ||
let item: swc_allocator::boxed::Box<usize> = | ||
black_box(allocator.alloc(black_box(i))); | ||
vec.push(item); | ||
} | ||
}) | ||
} | ||
|
||
fn direct_alloc_scoped(b: &mut Bencher, times: usize) { | ||
b.iter(|| { | ||
let allocator = MemorySpace::default(); | ||
|
||
allocator.scope(|| { | ||
let mut vec = swc_allocator::vec::Vec::new(); | ||
|
||
for i in 0..times { | ||
let item: swc_allocator::boxed::Box<usize> = | ||
black_box(swc_allocator::boxed::Box::new(black_box(i))); | ||
vec.push(item); | ||
} | ||
}); | ||
}) | ||
} | ||
|
||
fn fast_alloc_scoped(b: &mut Bencher, times: usize) { | ||
b.iter(|| { | ||
MemorySpace::default().scope(|| { | ||
let allocator = FastAlloc::default(); | ||
|
||
let mut vec = allocator.vec(); | ||
|
||
for i in 0..times { | ||
let item: swc_allocator::boxed::Box<usize> = | ||
black_box(allocator.alloc(black_box(i))); | ||
vec.push(item); | ||
} | ||
}); | ||
}) | ||
} | ||
|
||
c.bench_function("common/allocator/alloc/std/1000000", |b| { | ||
direct_alloc_std(b, 1000000) | ||
}); | ||
c.bench_function("common/allocator/alloc/no-scope/1000000", |b| { | ||
direct_alloc_no_scope(b, 1000000) | ||
}); | ||
c.bench_function("common/allocator/alloc/scoped/1000000", |b| { | ||
direct_alloc_scoped(b, 1000000) | ||
}); | ||
|
||
c.bench_function("common/allocator/alloc/cached-no-scope/1000000", |b| { | ||
fast_alloc_no_scope(b, 1000000) | ||
}); | ||
c.bench_function("common/allocator/alloc/cached-scoped/1000000", |b| { | ||
fast_alloc_scoped(b, 1000000) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, bench_alloc); | ||
criterion_main!(benches); |
This file contains 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 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 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 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
Oops, something went wrong.