about summary refs log tree commit diff
path: root/tvix/eval/src/vm.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-12-29T11·44+0300
committertazjin <tazjin@tvl.su>2022-12-29T12·27+0000
commit5d73c06b1a67bce68dcc0b2bd5f087ce00ab6317 (patch)
tree62d40c8ca8e1620bff028c8d89a5a0f05ee00661 /tvix/eval/src/vm.rs
parent6ab8320f075e36f2328a86f5fcf7674844a0bd12 (diff)
refactor(tvix/eval): use im::Vector for NixList representation r/5534
This is a persistent, structurally sharing data structure which is
more efficient in some of our use-cases. I have verified the
efficiency improvement using `hyperfine` repeatedly over expressions
on nixpkgs.

Lists are not the most performance-critical structure in Nix (that
would be attribute sets), but we can already see a small (~5-10%)
improvement.

Note that there are a handful of cases where we still go via `Vec`
that need to be fixed, most notable for `builtins.sort` which can not
currently be implemented directly using `im::Vector` because of a
restrictive type bound.

Change-Id: I237cc50cbd7629a046e5a5e4601fbb40355e551d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7670
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/vm.rs')
-rw-r--r--tvix/eval/src/vm.rs7
1 files changed, 3 insertions, 4 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index f1dc99439638..5bc0f7736ae4 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -815,10 +815,9 @@ impl<'o> VM<'o> {
             }
 
             OpCode::OpConcat => {
-                let rhs = fallible!(self, self.pop().to_list());
-                let mut lhs = fallible!(self, self.pop().to_list()).into_vec();
-                lhs.extend_from_slice(&rhs);
-                self.push(Value::List(NixList::from(lhs)))
+                let rhs = fallible!(self, self.pop().to_list()).into_inner();
+                let lhs = fallible!(self, self.pop().to_list()).into_inner();
+                self.push(Value::List(NixList::from(lhs + rhs)))
             }
 
             OpCode::OpInterpolate(Count(count)) => self.run_interpolate(count)?,