tomoyanonymous / mimium-rs

minimal musical medium- an infrastructural language for sound and music.
Mozilla Public License 2.0
9 stars 1 forks source link

mimalloc as global allocator #85

Closed tomoyanonymous closed 2 weeks ago

tomoyanonymous commented 3 weeks ago

This PR adds mimalloc by Microsoft as a default memory allocator.

https://docs.rs/mimalloc/latest/mimalloc/

mimalloc is suitable for a VM's allocator as it's initially designed for Koka, it improve performance when the allocation size is small.

before

test tests::parse::bench_many_symbols10 ... bench:   8,330,289.60 ns/iter (+/- 545,905.39)
test tests::parse::bench_many_symbols5  ... bench:   2,473,266.70 ns/iter (+/- 62,802.59)
test tests::parse::bench_many_symbols3  ... bench:   1,072,679.20 ns/iter (+/- 40,947.95)
test tests::runtime::bench_multiosc15   ... bench:       5,464.05 ns/iter (+/- 126.53)
test tests::runtime::bench_multiosc10   ... bench:       3,674.98 ns/iter (+/- 1,237.57)
test tests::runtime::bench_multiosc7    ... bench:       2,580.49 ns/iter (+/- 200.76)
test tests::runtime::bench_multiosc5    ... bench:       1,852.25 ns/iter (+/- 49.89)
test tests::scheduler_counter ... bench:     494,956.25 ns/iter (+/- 11,030.16)

after

test tests::parse::bench_many_symbols10 ... bench:   7,056,516.70 ns/iter (+/- 1,743,678.40)
test tests::parse::bench_many_symbols5  ... bench:   2,043,204.20 ns/iter (+/- 109,519.89)
test tests::parse::bench_many_symbols3  ... bench:     884,628.12 ns/iter (+/- 99,362.72)
test tests::runtime::bench_multiosc15   ... bench:       5,232.11 ns/iter (+/- 73.01)
test tests::runtime::bench_multiosc10   ... bench:       3,506.63 ns/iter (+/- 83.76)
test tests::runtime::bench_multiosc7    ... bench:       2,471.13 ns/iter (+/- 48.06)
test tests::runtime::bench_multiosc5    ... bench:       1,775.10 ns/iter (+/- 32.78)
test tests::scheduler_counter ... bench:     403,322.90 ns/iter (+/- 27,579.60)
tomoyanonymous commented 2 weeks ago

I'm going to merge this though there was not much significant performance improvement. Maybe we should prepare the test case that hit to the worst-case performance of the allocator somehow.