Truly independent web browser
LibJS: Shrink what compiled code keeps for the functions it creates
Andreas Klingcebb6398305e
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/scope.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/scope.rsindex 3c09acd0e82..085105ffbed 100644--- a/Libraries/LibJS/Rust/src/bytecode/codegen/scope.rs+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/scope.rs@@ -1941,7 +1941,7 @@ impl Generator<'_> {NestedFunctionName::None => None,NestedFunctionName::Identifier(name) => Some(self.context.names.identifier_fly_string(tree, name)),NestedFunctionName::Field(name, is_private) => {- field_name = name.map(|name| (name, is_private));+ field_name = name.map(|name| Box::new((name, is_private)));Some(ak::Utf16FlyString::from_utf8("field"))}};diff --git a/Libraries/LibJS/Rust/src/bytecode/executable_data.rs b/Libraries/LibJS/Rust/src/bytecode/executable_data.rsindex 8a695f49168..091545ffac2 100644--- a/Libraries/LibJS/Rust/src/bytecode/executable_data.rs+++ b/Libraries/LibJS/Rust/src/bytecode/executable_data.rs@@ -14,7 +14,6 @@ use super::constant::AbstractOperationKind;use super::constant::WellKnownSymbolKind;use super::operand::PropertyKeyTableIndex;use super::source_map::{SourceMapEntries, SourceOffset};-use crate::ast::FunctionId;use crate::compile::SharedFunctionDescription;use crate::compile::utf16_string_memory_size;use crate::layout::buffer::BlockSlice;@@ -56,14 +55,16 @@ pub enum ConstantValue {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,pub description: SharedFunctionDescription,- pub class_field_initializer_name: Option<(Utf16String, bool)>,+ /// The name of the class field whose initializer the function is, and whether the name is private.+ pub class_field_initializer_name: Option<Box<(Utf16String, bool)>>,pub should_eager_compile: bool,pub precompiled_function: Option<Arc<PrecompiledFunction>>,}+// NB: Code has these bytes for every function it creates, until the code is linked for the last time.+const _: () = assert!(size_of::<PendingSharedFunctionData>() == 64);+/// Metadata computed from scope analysis for a SharedFunctionInstanceData.#[derive(Clone)]pub struct FunctionSfdMetadata {diff --git a/Libraries/LibJS/Rust/src/compile.rs b/Libraries/LibJS/Rust/src/compile.rsindex 43fa5dea535..6c4bb710fc2 100644--- a/Libraries/LibJS/Rust/src/compile.rs+++ b/Libraries/LibJS/Rust/src/compile.rs@@ -1154,8 +1154,8 @@ pub struct SharedFunctionDescription {pub strict: bool,pub is_arrow: bool,pub has_simple_parameter_list: bool,- pub source_text_offset: usize,- pub source_text_length: usize,+ pub source_text_offset: u32,+ pub source_text_length: u32,pub uses_this: bool,pub uses_this_from_environment: bool,pub payload: Arc<FunctionPayload>,@@ -1179,8 +1179,8 @@ pub fn describe_shared_function(enclosing_code: &Arc<EnclosingCode>,) -> SharedFunctionDescription {let function_data = tree.function(function);- let source_start = function_data.source_text_start as usize;- let source_end = function_data.source_text_end as usize;+ let source_start = function_data.source_text_start;+ let source_end = function_data.source_text_end;let name = if let Some(name) = name_override {name@@ -1224,9 +1224,8 @@ pub(crate) fn pending_function_of_row(let index = &script.index;let at = row as usize;let flags = index.flags[at];- let (start, end) = (index.start[at] as usize, index.end[at] as usize);+ let (start, end) = (index.start[at], index.end[at]);PendingSharedFunctionData {- function: FunctionId::function(0),description: SharedFunctionDescription {name: name.unwrap_or_default(),function_kind: ast::FunctionKind::from_async_generator(@@ -1274,7 +1273,6 @@ impl PendingSharedFunctionData {enclosing_code,);Self {- function,description,class_field_initializer_name: None,should_eager_compile: false,@@ -1289,7 +1287,7 @@ impl PendingSharedFunctionData {+ self.class_field_initializer_name.as_ref()- .map_or(0, |(name, _)| utf16_string_memory_size(name))+ .map_or(0, |field| size_of_val(&**field) + utf16_string_memory_size(&field.0))+ self.precompiled_function.as_ref()diff --git a/Libraries/LibJS/Rust/src/runtime/shared_function_instance_data.rs b/Libraries/LibJS/Rust/src/runtime/shared_function_instance_data.rsindex 37f788c44ac..1b10584cb11 100644--- a/Libraries/LibJS/Rust/src/runtime/shared_function_instance_data.rs+++ b/Libraries/LibJS/Rust/src/runtime/shared_function_instance_data.rs@@ -404,7 +404,8 @@ impl SharedFunctionInstanceData {}shared.storage.source_code.set(source_code.cloned());- shared.initialize_source_text_range(source_text_offset, source_text_length);+ shared.storage.source_text_offset.set(source_text_offset);+ shared.storage.source_text_length.set(source_text_length);shared}@@ -460,7 +461,8 @@ impl SharedFunctionInstanceData {source_code: Option<&Rc<SourceCode>>,) -> Gc<SharedFunctionInstanceData> {let shared = Self::create(vm, &pending.description, pending.is_strict_in(is_strict), source_code);- if let Some((name, is_private)) = &pending.class_field_initializer_name {+ if let Some(field) = &pending.class_field_initializer_name {+ let (name, is_private) = &**field;shared.set_class_field_initializer_name_from_utf16(&name.to_utf16(), *is_private);}if let Some(precompiled) = &pending.precompiled_function {@@ -478,7 +480,8 @@ impl SharedFunctionInstanceData {) -> Gc<SharedFunctionInstanceData> {let strict = pending.is_strict_in(is_strict);let shared = Self::create_from_owned_description(vm, pending.description, strict, source_code);- if let Some((name, is_private)) = &pending.class_field_initializer_name {+ if let Some(field) = &pending.class_field_initializer_name {+ let (name, is_private) = &**field;shared.set_class_field_initializer_name_from_utf16(&name.to_utf16(), *is_private);}if let Some(precompiled) = pending.precompiled_function {