diff options
author | Aspen Smith <root@gws.fyi> | 2024-02-13T19·59-0500 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-02-21T20·53+0000 |
commit | 5e31096154d32bf128f8eb172f84ca3b7b968bc8 (patch) | |
tree | af991a2428954e98599a061a49a08d80abdadac3 /tvix/glue/src/builtins/derivation.rs | |
parent | 77a6eb4f512b6d8ae94b82677d8efe3eacf8cfa8 (diff) |
feat(tvix/eval): Store string context alongside data r/7591
Previously, Nix strings were represented as a Box (within Value) pointing to a tuple of an optional context, and another Box pointing to the actual string allocation itself. This is pretty inefficient, both in terms of memory usage (we use 48 whole bytes for a None context!) and in terms of the extra indirection required to get at the actual data. It was necessary, however, because with native Rust DSTs if we had something like `struct NixString(Option<NixContext>, BStr)` we could only pass around *fat* pointers to that value (with the length in the pointer) and that'd make Value need to be bigger (which is a waste of both memory and cache space, since that memory would be unused for all other Values). Instead, this commit implements *manual* allocation of a packed string representation, with the length *in the allocation* as a field past the context. This requires a big old pile of unsafe Rust, but the payoff is clear: hello outpath time: [882.18 ms 897.16 ms 911.23 ms] change: [-15.143% -13.819% -12.500%] (p = 0.00 < 0.05) Performance has improved. Fortunately this change can be localized entirely within value/string.rs, since we were abstracting things out nicely. Change-Id: Ibf56dd16c9c503884f64facbb7f0ac596463efb6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10852 Tested-by: BuildkiteCI Reviewed-by: raitobezarius <tvl@lahfa.xyz> Autosubmit: aspen <root@gws.fyi>
Diffstat (limited to 'tvix/glue/src/builtins/derivation.rs')
-rw-r--r-- | tvix/glue/src/builtins/derivation.rs | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/tvix/glue/src/builtins/derivation.rs b/tvix/glue/src/builtins/derivation.rs index b597d20211e9..71249f1c7722 100644 --- a/tvix/glue/src/builtins/derivation.rs +++ b/tvix/glue/src/builtins/derivation.rs @@ -485,28 +485,24 @@ pub(crate) mod derivation_builtins { .map(|(name, output)| { ( name.clone(), - ( - output.path.unwrap().to_absolute_path(), - Some( - NixContextElement::Single { - name, - derivation: drv_path.to_absolute_path(), - } - .into(), - ), - ) + NixString::new_context_from( + NixContextElement::Single { + name, + derivation: drv_path.to_absolute_path(), + } .into(), + output.path.unwrap().to_absolute_path(), + ), ) }) .collect(); new_attrs.push(( "drvPath".to_string(), - ( + NixString::new_context_from( + NixContextElement::Derivation(drv_path.to_absolute_path()).into(), drv_path.to_absolute_path(), - Some(NixContextElement::Derivation(drv_path.to_absolute_path()).into()), - ) - .into(), + ), )); Ok(Value::Attrs(Box::new(NixAttrs::from_iter( |