about summary refs log tree commit diff
path: root/tvix/eval/src/value/mod.rs
diff options
context:
space:
mode:
authorAspen Smith <root@gws.fyi>2024-02-01T17·28-0500
committeraspen <root@gws.fyi>2024-02-02T16·16+0000
commit5f0f4ea3746d6107839454bb5f4967d8757f5bb8 (patch)
treee618eca064cb7e263c58136f2c07b1dead63f49c /tvix/eval/src/value/mod.rs
parent4c5d9fa356bcb6dcd746129dde934412b44fdd35 (diff)
refactor(tvix/eval): Box Value::String r/7467
NixString is *quite* large - like 80 bytes - because of the extra
capacity value for BString and because of the context. We want to keep
Value small since we're passing it around a lot, so let's box the
NixString inside Value::String to save on some memory, and make cloning
ostensibly a little cheaper

Change-Id: I343c8b4e7f61dc3dcbbaba4382efb3b3e5bbabb2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10729
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/value/mod.rs')
-rw-r--r--tvix/eval/src/value/mod.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs
index e9b509834273..e0c5a2f512cf 100644
--- a/tvix/eval/src/value/mod.rs
+++ b/tvix/eval/src/value/mod.rs
@@ -47,7 +47,7 @@ pub enum Value {
     Bool(bool),
     Integer(i64),
     Float(f64),
-    String(NixString),
+    String(Box<NixString>),
 
     #[serde(skip)]
     Path(Box<Path>),
@@ -186,7 +186,7 @@ where
     T: Into<NixString>,
 {
     fn from(t: T) -> Self {
-        Self::String(t.into())
+        Self::String(Box::new(t.into()))
     }
 }
 
@@ -327,7 +327,9 @@ impl Value {
             let value = if let Some(v) = vals.pop() {
                 v.force(co, span.clone()).await?
             } else {
-                return Ok(Value::String(NixString::new_context_from(context, result)));
+                return Ok(Value::String(Box::new(NixString::new_context_from(
+                    context, result,
+                ))));
             };
             let coerced: Result<BString, _> = match (value, kind) {
                 // coercions that are always done
@@ -335,7 +337,7 @@ impl Value {
                     if let Some(ctx) = s.context_mut() {
                         context = context.join(ctx);
                     }
-                    Ok(s.into())
+                    Ok((*s).into())
                 }
 
                 // TODO(sterni): Think about proper encoding handling here. This needs
@@ -692,7 +694,7 @@ impl Value {
     /// everytime you want a string.
     pub fn to_str(&self) -> Result<NixString, ErrorKind> {
         match self {
-            Value::String(s) if !s.has_context() => Ok(s.clone()),
+            Value::String(s) if !s.has_context() => Ok((**s).clone()),
             Value::Thunk(thunk) => Self::to_str(&thunk.value()),
             other => Err(type_error("contextless strings", other)),
         }
@@ -703,7 +705,7 @@ impl Value {
         NixString,
         "contextful string",
         Value::String(s),
-        s.clone()
+        (**s).clone()
     );
     gen_cast!(to_path, Box<Path>, "path", Value::Path(p), p.clone());
     gen_cast!(to_attrs, Box<NixAttrs>, "set", Value::Attrs(a), a.clone());