1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-15 06:52:43 +01:00
nix/src/libstore-tests
Sergei Zimmerman e1c9bc0ef6
libstore: Get rid of allocations in printString, allocate 2K bytes on the stack
Looking at perf:

   0.21 │       push   %rbp
   0.99 │       mov    %rsp,%rbp
        │       push   %r15
   0.25 │       push   %r14
        │       push   %r13
   0.49 │       push   %r12
   0.66 │       push   %rbx
   1.23 │       lea    -0x10000(%rsp),%r11
   0.23 │ 15:   sub    $0x1000,%rsp
   1.01 │       orq    $0x0,(%rsp)
  59.12 │       cmp    %r11,%rsp
   0.27 │     ↑ jne    15

Seems like 64K is too much to have on the stack for each invocation, considering
that only a minuscule number of allocations are actually larger than 4K.

There's actually no good reason this function should use so much stack space. Or
use small_string at all. Everything can be done in small chunks that don't require
any memory allocations and use up 2K bytes on the stack.

This patch also adds a microbenchmark for tracking the unparsing performance. Here
are the results for this change:

(Before)

BM_UnparseRealDerivationFile/hello         7275 ns         7247 ns        96093 bytes_per_second=232.136Mi/s
BM_UnparseRealDerivationFile/firefox      40538 ns        40376 ns        17327 bytes_per_second=378.534Mi/s

(After)

BM_UnparseRealDerivationFile/hello         3228 ns         3218 ns       215671 bytes_per_second=522.775Mi/s
BM_UnparseRealDerivationFile/firefox      39724 ns        39584 ns        17617 bytes_per_second=386.101Mi/s

This translates into nice evaluation performance improvements (compared to 18c3d2348f):

Benchmark 1: GC_INITIAL_HEAP_SIZE=8G old-nix/bin/nix-instantiate ../nixpkgs -A nixosTests.gnome --readonly-mode
  Time (mean ± σ):      3.111 s ±  0.021 s    [User: 2.513 s, System: 0.580 s]
  Range (min … max):    3.083 s …  3.143 s    10 runs

Benchmark 2: GC_INITIAL_HEAP_SIZE=8G result/bin/nix-instantiate ../nixpkgs -A nixosTests.gnome --readonly-mode
  Time (mean ± σ):      3.037 s ±  0.038 s    [User: 2.461 s, System: 0.558 s]
  Range (min … max):    2.960 s …  3.086 s    10 runs
2025-08-31 00:48:37 +03:00
..
data libstore-tests: Obfuscate derivation paths in drv files for benchmarks 2025-08-17 16:57:04 +03:00
pch libstore-tests: Improve compile times with PCH 2025-08-17 01:08:31 +03:00
.version Move unit tests to the location Meson expects them to be 2024-10-17 15:42:16 -04:00
bench-main.cc libstore-tests: Split bench-main into a separate file 2025-08-03 01:03:40 +03:00
common-protocol.cc Make a few more things use StoreDirConfig instead of Store 2025-08-15 15:35:51 -04:00
content-address.cc Apply clang-format universally. 2025-07-18 12:47:27 -04:00
derivation-advanced-attrs.cc Store StructuredAttrs directly in Derivation 2025-07-29 17:28:16 -04:00
derivation-parser-bench.cc libstore: Get rid of allocations in printString, allocate 2K bytes on the stack 2025-08-31 00:48:37 +03:00
derivation.cc Store StructuredAttrs directly in Derivation 2025-07-29 17:28:16 -04:00
derived-path.cc Apply clang-format universally. 2025-07-18 12:47:27 -04:00
downstream-placeholder.cc Apply clang-format universally. 2025-07-18 12:47:27 -04:00
http-binary-cache-store.cc Rewrite StoreConfig::getUri in terms of new StoreConfig::getReference 2025-08-13 19:06:59 -04:00
legacy-ssh-store.cc treewide: Remove getUri and replace with getHumanReadableURI where appropriate 2025-08-14 16:47:05 +03:00
local-binary-cache-store.cc Expose the nix component in header include paths 2025-04-01 11:40:42 -04:00
local-overlay-store.cc libstore-tests: Restore commented out tests 2025-08-11 20:44:29 +03:00
local-store.cc libstore-tests: Restore commented out tests 2025-08-11 20:44:29 +03:00
machines.cc Add user@address:port support 2025-08-06 23:48:14 +03:00
meson.build Merge pull request #13795 from xokdvium/factor-out-s3url 2025-08-19 17:28:52 -04:00
meson.options add derivation parser benchmark 2025-07-29 16:51:55 +02:00
nar-info-disk-cache.cc Apply clang-format universally. 2025-07-18 12:47:27 -04:00
nar-info.cc Apply clang-format universally. 2025-07-18 12:47:27 -04:00
nix-meson-build-support rename: build-utils-meson -> nix-meson-build-support 2024-12-09 16:54:42 +01:00
nix_api_store.cc treewide: Remove getUri and replace with getHumanReadableURI where appropriate 2025-08-14 16:47:05 +03:00
outputs-spec.cc Apply clang-format universally. 2025-07-18 12:47:27 -04:00
package.nix flake: Apply nixfmt 1.0.0 2025-08-18 20:29:45 +03:00
path-info.cc Apply clang-format universally. 2025-07-18 12:47:27 -04:00
path.cc Apply clang-format universally. 2025-07-18 12:47:27 -04:00
ref-scan-bench.cc libutil: Move references.{hh,cc} to libstore 2025-08-08 10:30:09 +03:00
references.cc libutil: Move references.{hh,cc} to libstore 2025-08-08 10:30:09 +03:00
s3-binary-cache-store.cc Clean some header related things. 2025-04-06 18:53:38 -04:00
s3.cc Fix ParsedURL handling of %2F in URL paths 2025-08-28 22:20:04 +03:00
serve-protocol.cc Make a few more things use StoreDirConfig instead of Store 2025-08-15 15:35:51 -04:00
ssh-store.cc treewide: Remove getUri and replace with getHumanReadableURI where appropriate 2025-08-14 16:47:05 +03:00
store-reference.cc lib{store,flake}-tests: Add test for spaces in URIs 2025-07-18 21:23:35 +03:00
uds-remote-store.cc libstore-tests: Restore commented out tests 2025-08-11 20:44:29 +03:00
worker-protocol.cc Make a few more things use StoreDirConfig instead of Store 2025-08-15 15:35:51 -04:00