From c5961e77749d1d002a5e747468b87c34a32821f3 Mon Sep 17 00:00:00 2001 From: sterni Date: Wed, 23 Aug 2023 15:06:05 +0200 Subject: docs(tvix/eval): optimization potential for inherit (from) exprs Change-Id: Ibddaa111a5b7a86c42dbe153ae8e53f9a5601a54 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10112 Tested-by: BuildkiteCI Reviewed-by: Adam Joseph --- tvix/eval/docs/known-optimisation-potential.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tvix/eval/docs') diff --git a/tvix/eval/docs/known-optimisation-potential.md b/tvix/eval/docs/known-optimisation-potential.md index e2e0497aee..951771e739 100644 --- a/tvix/eval/docs/known-optimisation-potential.md +++ b/tvix/eval/docs/known-optimisation-potential.md @@ -138,3 +138,22 @@ optimisations, but note the most important ones here. determining if finalisation is necessary or not. This wouldn't be necessary if `OpFinalise` would just noop on any values that don't need to be finalised (anymore). + +* Phantom binding for from expression of inherits [easy] + + The from expression of an inherit is reevaluated for each inherit. This can + be demonstrated using the following Nix expression which, counter-intuitively, + will print “plonk” twice. + + ```nix + let + inherit (builtins.trace "plonk" { a = null; b = null; }) a b; + in + builtins.seq a (builtins.seq b null) + ``` + + In most Nix code, the from expression is just an identifier, so it is not + terribly inefficient, but in some cases a more expensive expression may + be used. We should create a phantom binding for the from expression that + is reused in the inherits, so only a single thunk is created for the from + expression. -- cgit 1.4.1