diff options
author | pennae <github@quasiparticle.net> | 2021-12-27 02:04:49 +0100 |
---|---|---|
committer | pennae <github@quasiparticle.net> | 2022-01-12 10:07:21 +0100 |
commit | 5838354d342f1cdd09da7099e86123b36ecec409 (patch) | |
tree | ebb68fd2ba7e9b29a10b36a90429b94c8efa1515 /src/libutil | |
parent | 26a8b220eb7470e132b9bcedb94b58492cdd786f (diff) |
optimize ExprConcatStrings::eval
constructing an ostringstream for non-string concats (like integer addition) is
a small constant cost that we can avoid. for string concats we can keep all the
string temporaries we get from coerceToString and concatenate them in one go,
which saves a lot of intermediate temporaries and copies in ostringstream. we
can also avoid copying the concatenated string again by directly allocating it
in GC memory and moving ownership of the concatenated string into the target
value.
saves about 2% on system eval.
before:
Benchmark 1: nix eval --raw --impure --expr 'with import <nixpkgs/nixos> {}; system'
Time (mean ± σ): 2.837 s ± 0.031 s [User: 2.562 s, System: 0.191 s]
Range (min … max): 2.796 s … 2.892 s 20 runs
after:
Benchmark 1: nix eval --raw --impure --expr 'with import <nixpkgs/nixos> {}; system'
Time (mean ± σ): 2.790 s ± 0.035 s [User: 2.532 s, System: 0.187 s]
Range (min … max): 2.722 s … 2.836 s 20 runs
Diffstat (limited to 'src/libutil')
0 files changed, 0 insertions, 0 deletions