1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-07 09:31:01 +01:00
nix/src
Sergei Zimmerman 5ea81f5b8f
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
2025-05-15 23:07:25 +00:00
..
build-remote Split out store-open.hh and store-registration.hh 2025-05-14 16:07:57 -04: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 Split out store-open.hh and store-registration.hh 2025-05-14 16:07:57 -04:00
libexpr Split out store-open.hh and store-registration.hh 2025-05-14 16:07:57 -04:00
libexpr-c Docs 2025-04-02 18:02:32 +02:00
libexpr-test-support Expose the nix component in header include paths 2025-04-01 11:40:42 -04:00
libexpr-tests libexpr: fix UB in builtins.ceil and builtins.floor 2025-04-13 04:36:09 +02:00
libfetchers Simplify registerInputScheme() 2025-05-05 08:35:59 +02:00
libfetchers-c nix-fetchers-c: Init with settings object 2025-04-02 18:29:42 +02:00
libfetchers-tests Drop fs alias in favour of std::filesystem 2025-05-01 14:24:34 +02:00
libflake Backward compatibility hack for dealing with dir in URL-style flakerefs 2025-05-09 10:10:42 +02:00
libflake-c Fix flake-c out of bounds access 2025-04-25 17:07:32 +02:00
libflake-tests nix-flake-c: Add lock flags 2025-04-02 18:29:42 +02:00
libmain treewide: Use StringSet alias consistently instead of std::set<std::string> 2025-05-02 17:40:29 +00:00
libmain-c Expose the nix component in header include paths 2025-04-01 11:40:42 -04:00
libstore Merge pull request #13196 from Mic92/store-config-base 2025-05-15 12:03:11 +02:00
libstore-c Split out store-open.hh and store-registration.hh 2025-05-14 16:07:57 -04:00
libstore-test-support Split out store-open.hh and store-registration.hh 2025-05-14 16:07:57 -04:00
libstore-tests libstore: Introduce WorkerProto::FeatureSet alias 2025-05-02 17:40:34 +00:00
libutil libexpr: Actually cache line information in PosTable 2025-05-15 23:07:25 +00:00
libutil-c Expose the nix component in header include paths 2025-04-01 11:40:42 -04:00
libutil-test-support Merge pull request #12877 from roberth/c-api-libflake-override-input 2025-04-08 09:01:51 +02:00
libutil-tests add DirectoryIterator to re-throw std::filesystem::filesystem_error 2025-05-01 11:54:13 +02:00
nix Split out store-open.hh and store-registration.hh 2025-05-14 16:07:57 -04:00
nix-build Split out store-open.hh and store-registration.hh 2025-05-14 16:07:57 -04:00
nix-channel Split out store-open.hh and store-registration.hh 2025-05-14 16:07:57 -04:00
nix-collect-garbage Split out store-open.hh and store-registration.hh 2025-05-14 16:07:57 -04:00
nix-copy-closure Split out store-open.hh and store-registration.hh 2025-05-14 16:07:57 -04:00
nix-env Split out store-open.hh and store-registration.hh 2025-05-14 16:07:57 -04:00
nix-instantiate Split out store-open.hh and store-registration.hh 2025-05-14 16:07:57 -04:00
nix-store Split out store-open.hh and store-registration.hh 2025-05-14 16:07:57 -04: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