Changes global allocator to mimalloc, improving performance.#9415
Changes global allocator to mimalloc, improving performance.#9415fdncred merged 3 commits intonushell:mainfrom
Conversation
|
I gave it a try on my mac but used |
30% faster, even better 🔥🔥🔥 |
|
Same test (with config files) on Windows 11 laptop It's a little shocking how much faster it is. |
|
@FilipAndersson245 The current thinking is that we want to wait and try this after the next release. JT has seen some projects switch allocators and have odd issues. I'm wondering if there's any way to create tests for this allocator in order to avoid such problems? Another question is if this allocator is supported on all our platforms that we release to. And here's another point that was brought up, "I am not sure about is if setting the rust level global allocator messes with tooling that instruments allocations." |
seems reasonable, After switching, it still works with tool such as valgrind, maybe this could be merged, and then yanked before release if it shows to produce problems 🤔. I agree tests would be nice, I'm unsure about how the global alloc is set, as its done in the main.rs file, if it is applied to tests, and benchmarks, or just the bin. its surprising that you got such a large reduction in startup time @fdncred. It seem alot of overhead in Nushell is from allocations. |
|
Thanks for your other comments. I'll pass that along.
I'm assuming this is because that i'm loading a few completion files, a few modules, a few scripts where most people may not load all that stuff. But that is just a guess.
We have a nightly CI that runs now. Maybe we'll be able to see if it fails tomorrow? |
that would be nice,
Great that it performs better in more real usecases 🔥 |
|
BTW: The nightly CI may work when it's get merged to main branch |
I thought it was already merged? |
The nightly CI was merged, I mean this PR will be checked by the CI after it's been merged |
|
So we merge this and if problems are found we yank it before next release? @fdncred |
|
@FilipAndersson245 I've been looking into this a bit more. Here's what I'd like to do for now. Following how qsv uses different allocators, I think it would nice to enable this functionality behind some features. So, that would mean something like this. mimalloc = { version = "0.1", default-features = false, optional = true }
jemallocator = { version = "0.5", optional = true }and in the code #[cfg(feature = "mimalloc")]
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
#[cfg(feature = "jemallocator")]
#[global_allocator]
static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;The difference in qsv vs nushell is that I think it would be good to initially default to the rust "standard" allocator, but have mimalloc and jemallocator in features so that we could compile with any of the 3 allocators for testing. Searching the qsv repo also revealed this in qsv-x86_64-pc-windows-gnu.txt |
|
One other thing. If you can make these changes, please ensure that the feature shows up when we run the |
|
did a comparason with jemalloc included, it beformed worse then baseline
should we include it for completeness sake? |
|
I would say no. Having two features that collide is also a cargo crime as cargo assumes that all features are additive only. |
|
Should we enable the feature in some nightly build and see if something blows up? |
Ya, that would be good. We just added nushell/nightlies. |
|
Nightly release of today: https://github.com/nushell/nightly/releases/tag/nightly-b907bf3 |
awesome, where can we tweak the feature parameters, or is that already included in those builds? |
I'm afraid we can't tweak the feature parameters currently, you can get some information from: https://github.com/nushell/nushell/blob/main/.github/workflows/release-pkg.nu |
<!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR makes `mimalloc` the default allocator, it has been the default on the nightly builds of nushell now for a couple of months and the performance improvements are quite nice, measuring upwards of 30% faster startup time on Windows, and a bit smaller on Linux, #9415 # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
<!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This PR makes `mimalloc` the default allocator, it has been the default on the nightly builds of nushell now for a couple of months and the performance improvements are quite nice, measuring upwards of 30% faster startup time on Windows, and a bit smaller on Linux, nushell#9415 # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
Description
this PR makes nushell use mimalloc as the default allocator, this has the benefit of reducing startup time on my machine.
17%on linux and22%on windows, when testing using hyperfine.the overhead to compile seem to be quite small, aswell as the increase of binary size quite small
on linux the binary went from
33.1mbto33.2mblinux

windows

User-Facing Changes
Tests + Formatting
After Submitting