1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-22 02:09:36 +01:00
nix/src
Sergei Zimmerman ef8dc34bd0 libexpr: Actually cache line information in PosTable
Previous code had a sneaky bug due to which no caching
actually happened:

```cpp
auto linesForInput = (*lines)[origin->offset];
```

That should have been:
```cpp
auto & linesForInput = (*lines)[origin->offset];
```

See [1].

Now that it also makes sense to make the cache bound in side
in order not to memoize all the sources without freeing any memory.
The default cache size has been chosen somewhat arbitrarily to be ~64k
origins. For reference, 25.05 nixpkgs has ~50k .nix files.

Simple benchmark:

```nix
let
  pkgs = import <nixpkgs> { };
in
builtins.foldl' (acc: el: acc + el.line) 0 (
  builtins.genList (x: builtins.unsafeGetAttrPos "gcc" pkgs) 10000
)
```

(After)

```
$ hyperfine "result/bin/nix eval -f ./test.nix"
Benchmark 1: result/bin/nix eval -f ./test.nix
  Time (mean ± σ):     292.7 ms ±   3.9 ms    [User: 131.0 ms, System: 120.5 ms]
  Range (min … max):   288.1 ms … 300.5 ms    10 runs
```

(Before)

```
hyperfine "nix eval -f ./test.nix"
Benchmark 1: nix eval -f ./test.nix
  Time (mean ± σ):     666.7 ms ±   6.4 ms    [User: 428.3 ms, System: 191.2 ms]
  Range (min … max):   659.7 ms … 681.3 ms    10 runs
```

If the origin happens to be a `all-packages.nix` or similar in size then the
difference is much more dramatic.

[1]: 22e3f0e987

(cherry picked from commit 5ea81f5b8f)
2025-07-30 11:51:53 +00:00
..
build-remote Apply clang-format universally. 2025-07-18 22:49:40 +03:00
external-api-docs Format .nix files 2025-01-24 17:04:02 +01:00
internal-api-docs Format .nix files 2025-01-24 17:04:02 +01:00
libcmd Apply clang-format universally. 2025-07-18 22:49:40 +03:00
libexpr Apply clang-format universally. 2025-07-18 22:49:40 +03:00
libexpr-c Apply clang-format universally. 2025-07-18 22:49:40 +03:00
libexpr-test-support Apply clang-format universally. 2025-07-18 22:49:40 +03:00
libexpr-tests Apply clang-format universally. 2025-07-18 22:49:40 +03:00
libfetchers Apply clang-format universally. 2025-07-18 22:49:40 +03:00
libfetchers-c nix-fetchers-c: Init with settings object 2025-04-02 18:29:42 +02:00
libfetchers-tests Apply clang-format universally. 2025-07-18 22:49:40 +03:00
libflake Apply clang-format universally. 2025-07-18 22:49:40 +03:00
libflake-c Fix flake-c out of bounds access 2025-04-25 17:07:32 +02:00
libflake-tests Apply clang-format universally. 2025-07-18 22:49:40 +03:00
libmain Apply clang-format universally. 2025-07-18 22:49:40 +03:00
libmain-c Expose the nix component in header include paths 2025-04-01 11:40:42 -04:00
libstore treewide: Fix Meson CPU names for powerpc CPUs 2025-07-21 22:49:14 +00:00
libstore-c Split out store-open.hh and store-registration.hh 2025-05-14 16:07:57 -04:00
libstore-test-support Apply clang-format universally. 2025-07-18 22:49:40 +03:00
libstore-tests Apply clang-format universally. 2025-07-18 22:49:40 +03:00
libutil libexpr: Actually cache line information in PosTable 2025-07-30 11:51:53 +00:00
libutil-c Apply clang-format universally. 2025-07-18 22:49:40 +03:00
libutil-test-support Apply clang-format universally. 2025-07-18 22:49:40 +03:00
libutil-tests Apply clang-format universally. 2025-07-18 22:49:40 +03:00
nix Apply clang-format universally. 2025-07-18 22:49:40 +03:00
nix-build Apply clang-format universally. 2025-07-18 22:49:40 +03:00
nix-channel Apply clang-format universally. 2025-07-18 22:49:40 +03:00
nix-collect-garbage Apply clang-format universally. 2025-07-18 22:49:40 +03:00
nix-copy-closure Split out store-open.hh and store-registration.hh 2025-05-14 16:07:57 -04:00
nix-env Apply clang-format universally. 2025-07-18 22:49:40 +03:00
nix-instantiate Apply clang-format universally. 2025-07-18 22:49:40 +03:00
nix-store Apply clang-format universally. 2025-07-18 22:49:40 +03:00
perl Split out store-open.hh and store-registration.hh 2025-05-14 16:07:57 -04:00
nix-functional-tests Build Functional tests with Meson 2024-08-14 15:35:40 -04:00
nix-manual Build the manual with Meson 2024-10-09 11:58:17 -04:00