From 3c2a2bb39f94a17bbb21268d5ca6228486507c40 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 5 Apr 2025 21:35:32 +0200 Subject: [PATCH] LibJS: Shrink JS::Bytecode::Operand from 8 bytes to 4 bytes This packs the bytecode much better and gives us a decent performance boost on throughput-focused benchmarks. Measured on my M3 MacBook Pro: - 4.7% speedup on Kraken - 2.3% speedup on Octane - 2.7% speedup on JetStream1 --- Libraries/LibJS/Bytecode/Operand.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Libraries/LibJS/Bytecode/Operand.h b/Libraries/LibJS/Bytecode/Operand.h index e4f619969b6..c2826bc3814 100644 --- a/Libraries/LibJS/Bytecode/Operand.h +++ b/Libraries/LibJS/Bytecode/Operand.h @@ -13,7 +13,7 @@ namespace JS::Bytecode { class Operand { public: - enum class Type { + enum class Type : u8 { Invalid, Register, Local, @@ -26,6 +26,7 @@ public: : m_type(type) , m_index(index) { + VERIFY((index & 0x3fffffff) == index); } explicit Operand(Register); @@ -42,10 +43,12 @@ public: void offset_index_by(u32 offset) { m_index += offset; } private: - Type m_type {}; - u32 m_index { 0 }; + Type m_type : 2 {}; + u32 m_index : 30 { 0 }; }; +static_assert(sizeof(Operand) == 4); + } namespace AK {