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 <adam@westernsemico.com>
This commit is contained in:
parent
6b685ec4a5
commit
c5961e7774
1 changed files with 19 additions and 0 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue