From d91e5f904f2cf298683d42dd05195ba7a9042e1a Mon Sep 17 00:00:00 2001 From: tkshsbcue Date: Sun, 5 Apr 2026 10:51:07 +0530 Subject: [PATCH] perf(bytecompiler): avoid redundant Constant clone in IC initialization emit_get_property_by_name and emit_set_property_by_name were cloning the entire Constant enum just to extract the inner JsString, which was then cloned again for the InlineCache. Borrow the constant by reference instead and clone only the JsString once. --- core/engine/src/bytecompiler/mod.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/engine/src/bytecompiler/mod.rs b/core/engine/src/bytecompiler/mod.rs index db4607d1abd..8242b1f629c 100644 --- a/core/engine/src/bytecompiler/mod.rs +++ b/core/engine/src/bytecompiler/mod.rs @@ -988,10 +988,12 @@ impl<'ctx> ByteCompiler<'ctx> { let ic_index = self.ic.len() as u32; let name_index = self.get_or_insert_name(ident); - let Constant::String(ref name) = self.constants[name_index as usize].clone() else { + let Constant::String(name) = &self.constants[name_index as usize] else { unreachable!("there should be a string at index") }; - self.ic.push(InlineCache::new(name.clone())); + let is_length = *name == StaticJsStrings::LENGTH; + let name = name.clone(); + self.ic.push(InlineCache::new(name)); if let Some(receiver) = receiver { self.bytecode.emit_get_property_by_name_with_this( @@ -1000,7 +1002,7 @@ impl<'ctx> ByteCompiler<'ctx> { value.variable(), ic_index.into(), ); - } else if name == &StaticJsStrings::LENGTH { + } else if is_length { self.bytecode.emit_get_length_property( dst.variable(), value.variable(), @@ -1025,10 +1027,11 @@ impl<'ctx> ByteCompiler<'ctx> { let ic_index = self.ic.len() as u32; let name_index = self.get_or_insert_name(ident); - let Constant::String(ref name) = self.constants[name_index as usize].clone() else { + let Constant::String(name) = &self.constants[name_index as usize] else { unreachable!("there should be a string at index") }; - self.ic.push(InlineCache::new(name.clone())); + let name = name.clone(); + self.ic.push(InlineCache::new(name)); if let Some(receiver) = receiver { self.bytecode.emit_set_property_by_name_with_this(