From 61b8a9b2ba278f697735a2c3ff77fff091c8f464 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 5 Jan 2023 15:57:33 +0300 Subject: refactor(tvix/eval): short-circuit on empty attrs in compiler This is marginally more efficient and has simpler bytecode. Change-Id: Iad37c9aeef24583e8f696911bcd83d43639f2e36 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7769 Reviewed-by: raitobezarius Tested-by: BuildkiteCI Reviewed-by: flokli --- tvix/eval/src/compiler/bindings.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tvix/eval/src/compiler/bindings.rs b/tvix/eval/src/compiler/bindings.rs index 93b3dc3cc666..83667c129be0 100644 --- a/tvix/eval/src/compiler/bindings.rs +++ b/tvix/eval/src/compiler/bindings.rs @@ -640,6 +640,15 @@ impl Compiler<'_> { self.declare_namespaced_inherits(kind, inherit_froms, &mut bindings); self.declare_bindings(kind, &mut count, &mut bindings, node); + // Check if we can bail out on empty bindings + if count == 0 { + // still need an attrset to exist, but it is empty. + if kind.is_attrs() { + self.emit_constant(Value::Attrs(Box::new(NixAttrs::empty())), node); + return; + } + } + // Actually bind values and ensure they are on the stack. self.bind_values(bindings); -- cgit 1.4.1