Skip to content

Truly independent web browser

LibJS: Hold the constants of compiled code in 16 bytes

Andreas Kling21c8bf60af23
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/constants.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/constants.rs
index f7e407abfc9..a05e405ae4f 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/constants.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/constants.rs
@@ -258,7 +258,7 @@ impl ConstantTable {
}
pub(super) fn add_bigint(&mut self, value: String) -> Operand {
- Operand::constant(self.append(ConstantValue::BigInt(value)))
+ Operand::constant(self.append(ConstantValue::BigInt(Box::new(value.into_boxed_str()))))
}
pub(super) fn add_well_known_symbol(&mut self, symbol: WellKnownSymbolKind) -> Operand {
diff --git a/Libraries/LibJS/Rust/src/bytecode/executable_data.rs b/Libraries/LibJS/Rust/src/bytecode/executable_data.rs
index d2e7b74affa..8a695f49168 100644
--- a/Libraries/LibJS/Rust/src/bytecode/executable_data.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/executable_data.rs
@@ -44,13 +44,17 @@ pub enum ConstantValue {
Undefined,
Empty,
String(Utf16String),
- BigInt(String),
+ /// The text of the literal, boxed once more so that a constant takes 16 bytes: a BigInt literal is rare.
+ BigInt(Box<Box<str>>),
/// A VM-specific well-known symbol resolved when the Executable is materialized.
WellKnownSymbol(WellKnownSymbolKind),
/// A NativeJavaScriptBackedFunction intrinsic resolved when the Executable is materialized.
AbstractOperation(AbstractOperationKind),
}
+// NB: Every constant of code has these bytes, until the code is linked for the last time.
+const _: () = assert!(size_of::<ConstantValue>() == 16);
+
pub struct PendingSharedFunctionData {
/// The function in the tree of the compile job, for as long as that job runs.
pub function: FunctionId,
@@ -229,7 +233,7 @@ pub struct ExecutableData {
fn constant_memory_size(constant: &ConstantValue) -> usize {
match constant {
ConstantValue::String(string) => utf16_string_memory_size(string),
- ConstantValue::BigInt(literal) => literal.capacity(),
+ ConstantValue::BigInt(literal) => size_of::<Box<str>>() + literal.len(),
_ => 0,
}
}