Fork of Lix to retain it clean from idiot AI sloppers
0

Configure Feed

Select the types of activity you want to include in your feed.

build: use mimalloc

mimalloc is a compact general purpose allocator from Microsoft. It
consistently outperforms glibc's `malloc()` in allocation-heavy
workloads, such as Lix's evaluator

It's currently only linked in the main `nix` executable, as Boehm's GC
uses its own allocator. Other allocations that *do* go through glibc's
`malloc()` are still much faster, though

Benchmarked on x86_64-linux against Nixpkgs `bd07873`:

| attribute | thunks | lix@`1396012` | mimalloc | uplift |
|-------------------|---------|---------------|----------|--------|
| hello | 206444 | 0.726s | 0.620s | 1.17x |
| chromium | 1177382 | 2.273s | 2.136s | 1.06x |
| firefox-unwrapped | 1394797 | 2.521s | 2.378s | 1.06x |
| texliveFull | 3186440 | 4.992s | 4.672s | 1.07x |
| nixosTests.gnome | 7905808 | 6.115s | 5.723s | 1.07x |

Based-on: https://github.com/NixOS/nix/pull/15596
Co-authored-by: Bernardo Meurer Costa <beme@anthropic.com>
Change-Id: I3ad92eacc075efeaf3d9f7730ada7b29835536a4

+30 -1
+16
doc/manual/rl-next/mimalloc.md
··· 1 + --- 2 + synopsis: "Use mimalloc for faster evaluation" 3 + cls: [5645] 4 + category: Features 5 + credits: [getchoo, lovesegfault] 6 + --- 7 + 8 + Lix now links with [mimalloc](https://github.com/microsoft/mimalloc), 9 + replacing the system's default `malloc()` for all non-GC allocations. 10 + 11 + This yields a **5–12% wall-clock improvement** on evaluation workloads, 12 + ranging from `nix-instantiate hello` to `nix-env -qa` and full NixOS 13 + configurations. 14 + 15 + The allocator can be disabled at build time with `-Dmimalloc=disabled`, 16 + or by passing the `useMimalloc = false` override to the `lix` package.
+1
lix/nix/meson.build
··· 172 172 dependencies : [ 173 173 liblix, 174 174 boehm, 175 + mimalloc, 175 176 capnp_rpc, 176 177 nlohmann_json, 177 178 kj,
+2
meson.build
··· 352 352 boehm = dependency('bdw-gc', required : gc_opt, version : '>=8.2.6', include_type : 'system') 353 353 configdata.set('HAVE_BOEHMGC', boehm.found().to_int()) 354 354 355 + mimalloc = dependency('mimalloc', required: get_option('mimalloc')) 356 + 355 357 boost = dependency('boost', required : true, include_type : 'system') 356 358 kj = dependency('kj-async', required : true, include_type : 'system') 357 359 capnp = dependency('capnp', required : true, include_type : 'system')
+4
meson.options
··· 8 8 description : 'enable garbage collection in the Nix expression evaluator (requires Boehm GC)', 9 9 ) 10 10 11 + option('mimalloc', type: 'feature', value: 'auto', 12 + description: 'link against mimalloc to override the default memory allocator', 13 + ) 14 + 11 15 option('enable-embedded-sandbox-shell', type : 'boolean', value : false, 12 16 description : 'include the sandbox shell in the Nix binary', 13 17 )
+7 -1
package.nix
··· 42 42 cacert, 43 43 mercurial, 44 44 meson, 45 + mimalloc, 45 46 ninja, 46 47 openssl, 47 48 passt, ··· 75 76 76 77 # Support garbage collection in the evaluator. 77 78 enableGC ? sanitize == null || !builtins.elem "address" sanitize, 79 + # Whether to use mimalloc over the default `malloc` 80 + # Significantly improves evaluation performance on allocation-heavy workloads 81 + useMimalloc ? true, 78 82 # List of Meson sanitize options. Accepts values of b_sanitize, e.g. 79 83 # "address", "undefined", "thread". 80 84 # Enabling the "address" sanitizer will disable garbage collection in the evaluator. ··· 467 471 # so we must explicitly enable or disable features that we are not passing 468 472 # dependencies for. 469 473 (lib.mesonEnable "gc" enableGC) 474 + (lib.mesonEnable "mimalloc" useMimalloc) 470 475 (lib.mesonEnable "internal-api-docs" internalApiDocs) 471 476 (lib.mesonEnable "dtrace-probes" withDtrace) 472 477 (lib.mesonBool "enable-tests" (finalAttrs.finalPackage.doCheck || lintInsteadOfBuild)) ··· 574 579 ++ lib.optionals (finalAttrs.dontBuild) maybePropagatedInputs 575 580 # I am so sorry. This is because checkInputs are required to pass 576 581 # configure, but we don't actually want to *run* the checks here. 577 - ++ lib.optionals lintInsteadOfBuild finalAttrs.checkInputs; 582 + ++ lib.optionals lintInsteadOfBuild finalAttrs.checkInputs 583 + ++ lib.optional useMimalloc mimalloc; 578 584 579 585 checkInputs = [ 580 586 gtest