-
Notifications
You must be signed in to change notification settings - Fork 174
Replace malloc with mimalloc #142
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
Comments
We should do new benchmarks when considering something like this, FWIW. |
Using a custom allocator is problematic for libquickjs.a due to:
Embedders can replace the default allocator. That's something we could do in the qjs executable, although I'm in no rush to do that right now. Tangentially, I've spotted several places where quickjs mallocs a struct that mallocs a struct that mallocs a struct. There's likely gains to be had by flattening such allocation trees. |
There are indeed some optimisations we could do with the default allocators too but i think the difference is just huge when using mimalloc. |
@saghul So I did some benchmarks with current quickjs-ng
|
That's a very significant difference. Another allocator worth trying out is jemalloc. |
Perhaps as an optional dependency? Or an allocator system that lets you add a define to switch which malloc you're using? |
Already the case:
|
Even though you can replace the default allocator yourself which i have done already, making it default positions quickjs at a much better place in terms of performance for everyone and in various benchmarks. That's why i opened up this issue. |
While having good benchmark results it would be disingenuous to do that if it turns out it's tricky to use that allocator in all situations. That said, once I put the docs together, we can have a section where we mention things like this. |
@ammarahm-ed I want to benchmark something semi-related to this (using calloc vs malloc + memset to be precise). How did you get the results table from your first post? |
@saghul do you have binary or instructions to build I can test. I have write a benchmark script in https://github.com/gengjiawen/js-engines-playground/tree/main/benchmark |
This is the PR: #519 I'll take a look at your scripts, thank you! |
@gengjiawen Out of curiosity, where do those benchmarks come from? |
Use jsuv install engines,than run ‘node benchmark.js’ |
Sorry I meant that the actual benchmark itself, is it written by V8? What is its canonical source? |
https://github.com/mozilla/arewefastyet/tree/master/benchmarks/v8-v7 |
Thank you! I see they are deemed obsolete. Are they still relevant, at least in the case of QuickJS? |
Likely so. It’s https://bellard.org/quickjs/bench.html. I think maybe update v9 version. |
Gotcha. |
The V8 team stopped using them because they're not really representative of real web apps (fair enough) but they're still useful for benchmarking raw engine prowess. |
Some (unscientific) benchmark results: | Benchmark (Higher scores are better) | QuickJS | QuickJS (mimalloc) | |---------------------------------------|-------------------|--------------------| | Richards | 1217 | 1229 | | DeltaBlue | 1192 | 1297 | | Crypto | 1195 | 1191 | | RayTrace | 1477 | 2186 | | EarleyBoyer | 2441 | 3246 | | RegExp | 275 | 315 | | Splay | 2461 | 3765 | | NavierStokes | 2156 | 2119 | | Score | 1318 | 1553 | Running the V8 benchmark suite (version 7) on an M1 MacBook Pro. Fixes: #142
Some (unscientific) benchmark results: | Benchmark (Higher scores are better) | QuickJS | QuickJS (mimalloc) | |---------------------------------------|-------------------|--------------------| | Richards | 1217 | 1229 | | DeltaBlue | 1192 | 1297 | | Crypto | 1195 | 1191 | | RayTrace | 1477 | 2186 | | EarleyBoyer | 2441 | 3246 | | RegExp | 275 | 315 | | Splay | 2461 | 3765 | | NavierStokes | 2156 | 2119 | | Score | 1318 | 1553 | Running the V8 benchmark suite (version 7) on an M1 MacBook Pro. Fixes: quickjs-ng/quickjs#142
Uh oh!
There was an error while loading. Please reload this page.
Using mimalloc instead of malloc improves performance significantly.
Pros: Improved performance with a small change
Cons: It will add an external dependency and slightly increase size of QuickJS binaries.
It has been previously added here: openwebf/quickjs#30
Here's the benchmark I ran after replacing:
It could also be opt-in by the way.
The text was updated successfully, but these errors were encountered: