From 56f8d7c5bfc46182a644e7dd1404f931257b605d Mon Sep 17 00:00:00 2001 From: pdogr Date: Thu, 24 Mar 2022 02:48:46 +0530 Subject: [PATCH 1/2] [perf][vm] replace format! macro by &'static str, reducing one allocation per instruction execution --- boa_engine/src/vm/mod.rs | 2 +- boa_engine/src/vm/opcode.rs | 131 ++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 1 deletion(-) diff --git a/boa_engine/src/vm/mod.rs b/boa_engine/src/vm/mod.rs index bd8b6b1ff62..2eb81b32a8c 100644 --- a/boa_engine/src/vm/mod.rs +++ b/boa_engine/src/vm/mod.rs @@ -137,7 +137,7 @@ impl Context { opcode }; - let _timer = Profiler::global().start_event(&format!("INST - {}", opcode.as_str()), "vm"); + let _timer = Profiler::global().start_event(opcode.as_instruction_str(), "vm"); match opcode { Opcode::Nop => {} diff --git a/boa_engine/src/vm/opcode.rs b/boa_engine/src/vm/opcode.rs index 0020b640ac7..ff98f8fbbe0 100644 --- a/boa_engine/src/vm/opcode.rs +++ b/boa_engine/src/vm/opcode.rs @@ -1066,6 +1066,137 @@ impl Opcode { Opcode::Nop => "Nop", } } + + pub fn as_instruction_str(self) -> &'static str { + match self { + Opcode::Pop => "INST - Pop", + Opcode::Dup => "INST - Dup", + Opcode::Swap => "INST - Swap", + Opcode::PushZero => "INST - PushZero", + Opcode::PushOne => "INST - PushOne", + Opcode::PushInt8 => "INST - PushInt8", + Opcode::PushInt16 => "INST - PushInt16", + Opcode::PushInt32 => "INST - PushInt32", + Opcode::PushRational => "INST - PushRational", + Opcode::PushNaN => "INST - PushNaN", + Opcode::PushPositiveInfinity => "INST - PushPositiveInfinity", + Opcode::PushNegativeInfinity => "INST - PushNegativeInfinity", + Opcode::PushNull => "INST - PushNull", + Opcode::PushTrue => "INST - PushTrue", + Opcode::PushFalse => "INST - PushFalse", + Opcode::PushUndefined => "INST - PushUndefined", + Opcode::PushLiteral => "INST - PushLiteral", + Opcode::PushEmptyObject => "INST - PushEmptyObject", + Opcode::PushNewArray => "INST - PushNewArray", + Opcode::PushValueToArray => "INST - PushValueToArray", + Opcode::PushElisionToArray => "INST - PushElisionToArray", + Opcode::PushIteratorToArray => "INST - PushIteratorToArray", + Opcode::Add => "INST - Add", + Opcode::Sub => "INST - Sub", + Opcode::Div => "INST - Div", + Opcode::Mul => "INST - Mul", + Opcode::Mod => "INST - Mod", + Opcode::Pow => "INST - Pow", + Opcode::ShiftRight => "INST - ShiftRight", + Opcode::ShiftLeft => "INST - ShiftLeft", + Opcode::UnsignedShiftRight => "INST - UnsignedShiftRight", + Opcode::BitOr => "INST - BitOr", + Opcode::BitAnd => "INST - BitAnd", + Opcode::BitXor => "INST - BitXor", + Opcode::BitNot => "INST - BitNot", + Opcode::In => "INST - In", + Opcode::Eq => "INST - Eq", + Opcode::StrictEq => "INST - StrictEq", + Opcode::NotEq => "INST - NotEq", + Opcode::StrictNotEq => "INST - StrictNotEq", + Opcode::GreaterThan => "INST - GreaterThan", + Opcode::GreaterThanOrEq => "INST - GreaterThanOrEq", + Opcode::LessThan => "INST - LessThan", + Opcode::LessThanOrEq => "INST - LessThanOrEq", + Opcode::InstanceOf => "INST - InstanceOf", + Opcode::TypeOf => "INST - TypeOf", + Opcode::Void => "INST - Void", + Opcode::LogicalNot => "INST - LogicalNot", + Opcode::LogicalAnd => "INST - LogicalAnd", + Opcode::LogicalOr => "INST - LogicalOr", + Opcode::Coalesce => "INST - Coalesce", + Opcode::Pos => "INST - Pos", + Opcode::Neg => "INST - Neg", + Opcode::Inc => "INST - Inc", + Opcode::IncPost => "INST - IncPost", + Opcode::Dec => "INST - Dec", + Opcode::DecPost => "INST - DecPost", + Opcode::DefInitArg => "INST - DefInitArg", + Opcode::DefVar => "INST - DefVar", + Opcode::DefInitVar => "INST - DefInitVar", + Opcode::DefLet => "INST - DefLet", + Opcode::DefInitLet => "INST - DefInitLet", + Opcode::DefInitConst => "INST - DefInitConst", + Opcode::GetName => "INST - GetName", + Opcode::GetNameOrUndefined => "INST - GetNameOrUndefined", + Opcode::SetName => "INST - SetName", + Opcode::GetPropertyByName => "INST - GetPropertyByName", + Opcode::GetPropertyByValue => "INST - GetPropertyByValue", + Opcode::SetPropertyByName => "INST - SetPropertyByName", + Opcode::DefineOwnPropertyByName => "INST - DefineOwnPropertyByName", + Opcode::SetPropertyByValue => "INST - SetPropertyByValue", + Opcode::DefineOwnPropertyByValue => "INST - DefineOwnPropertyByValue", + Opcode::SetPropertyGetterByName => "INST - SetPropertyGetterByName", + Opcode::SetPropertyGetterByValue => "INST - SetPropertyGetterByValue", + Opcode::SetPropertySetterByName => "INST - SetPropertySetterByName", + Opcode::SetPropertySetterByValue => "INST - SetPropertySetterByValue", + Opcode::DeletePropertyByName => "INST - DeletePropertyByName", + Opcode::DeletePropertyByValue => "INST - DeletePropertyByValue", + Opcode::CopyDataProperties => "INST - CopyDataProperties", + Opcode::Jump => "INST - Jump", + Opcode::JumpIfFalse => "INST - JumpIfFalse", + Opcode::JumpIfNotUndefined => "INST - JumpIfNotUndefined", + Opcode::Throw => "INST - Throw", + Opcode::TryStart => "INST - TryStart", + Opcode::TryEnd => "INST - TryEnd", + Opcode::CatchStart => "INST - CatchStart", + Opcode::CatchEnd => "INST - CatchEnd", + Opcode::CatchEnd2 => "INST - CatchEnd2", + Opcode::FinallyStart => "INST - FinallyStart", + Opcode::FinallyEnd => "INST - FinallyEnd", + Opcode::FinallySetJump => "INST - FinallySetJump", + Opcode::ToBoolean => "INST - ToBoolean", + Opcode::This => "INST - This", + Opcode::Case => "INST - Case", + Opcode::Default => "INST - Default", + Opcode::GetFunction => "INST - GetFunction", + Opcode::GetGenerator => "INST - GetGenerator", + Opcode::Call => "INST - Call", + Opcode::CallWithRest => "INST - CallWithRest", + Opcode::New => "INST - New", + Opcode::NewWithRest => "INST - NewWithRest", + Opcode::Return => "INST - Return", + Opcode::PushDeclarativeEnvironment => "INST - PushDeclarativeEnvironment", + Opcode::PushFunctionEnvironment => "INST - PushFunctionEnvironment", + Opcode::PopEnvironment => "INST - PopEnvironment", + Opcode::LoopStart => "INST - LoopStart", + Opcode::LoopContinue => "INST - LoopContinue", + Opcode::LoopEnd => "INST - LoopEnd", + Opcode::ForInLoopInitIterator => "INST - ForInLoopInitIterator", + Opcode::InitIterator => "INST - InitIterator", + Opcode::IteratorNext => "INST - IteratorNext", + Opcode::IteratorNextFull => "INST - IteratorNextFull", + Opcode::IteratorClose => "INST - IteratorClose", + Opcode::IteratorToArray => "INST - IteratorToArray", + Opcode::ForInLoopNext => "INST - ForInLoopNext", + Opcode::ConcatToString => "INST - ConcatToString", + Opcode::RequireObjectCoercible => "INST - RequireObjectCoercible", + Opcode::ValueNotNullOrUndefined => "INST - ValueNotNullOrUndefined", + Opcode::RestParameterInit => "INST - FunctionRestParameter", + Opcode::RestParameterPop => "INST - RestParameterPop", + Opcode::PopOnReturnAdd => "INST - PopOnReturnAdd", + Opcode::PopOnReturnSub => "INST - PopOnReturnSub", + Opcode::Yield => "INST - Yield", + Opcode::GeneratorNext => "INST - GeneratorNext", + Opcode::GeneratorNextDelegate => "INST - GeneratorNextDelegate", + Opcode::Nop => "INST - Nop", + } + } } #[derive(Debug, Clone, Copy, PartialEq, Eq)] From dfaa29b76cac7fd604a378c47f75dd34c0b1d049 Mon Sep 17 00:00:00 2001 From: pdogr Date: Thu, 24 Mar 2022 17:54:42 +0530 Subject: [PATCH 2/2] [docs] add documentation for as_instruction_str method --- boa_engine/src/vm/opcode.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/boa_engine/src/vm/opcode.rs b/boa_engine/src/vm/opcode.rs index ff98f8fbbe0..03d30cbbe8e 100644 --- a/boa_engine/src/vm/opcode.rs +++ b/boa_engine/src/vm/opcode.rs @@ -1067,6 +1067,7 @@ impl Opcode { } } + /// Name of the profiler event for this opcode pub fn as_instruction_str(self) -> &'static str { match self { Opcode::Pop => "INST - Pop",