mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-12 09:56:45 +02:00
Generator::allocate_register used to scan the free pool to find the lowest-numbered register and then Vec::remove it, making every allocation O(n) in the size of the pool. When loading https://x.com/ on my Linux machine, we spent ~800ms in this function alone! This logic only existed to match the C++ register allocation ordering while transitioning from C++ to Rust in the LibJS compiler, so now we can simply get rid of it and make it instant. :^) So drop the "always hand out the lowest-numbered free register" policy and use the pool as a plain LIFO stack. Pushing and popping the back of the Vec are both O(1), and peak register usage is unchanged since the policy only affects which specific register gets reused, not how aggressively.
46 lines
1.0 KiB
Plaintext
46 lines
1.0 KiB
Plaintext
$9814d5bc nested-for-loop-completion.js:1:1
|
|
Registers: 9
|
|
Blocks: 8
|
|
Constants:
|
|
[0] = Int32(4)
|
|
[1] = Undefined
|
|
[2] = Int32(7)
|
|
[3] = Int32(1)
|
|
[4] = Int32(0)
|
|
[5] = Int32(2)
|
|
|
|
block0:
|
|
[ 0] SetGlobal `n`, src:Int32(4)
|
|
[ 18] Mov dst:reg5, src:Undefined
|
|
[ 28] Jump target:block3
|
|
|
|
block1:
|
|
[ 30] SetGlobal `depth`, src:Int32(0)
|
|
[ 48] Mov dst:reg6, src:Undefined
|
|
[ 58] Jump target:block6
|
|
|
|
block2:
|
|
[ 60] GetGlobal dst:reg7, `n`
|
|
[ 78] Add dst:reg6, lhs:reg7, rhs:Int32(1)
|
|
[ 88] SetGlobal `n`, src:reg6
|
|
|
|
block3:
|
|
[ a0] GetGlobal dst:reg6, `n`
|
|
[ b8] JumpLessThanEquals lhs:reg6, rhs:Int32(7), true_target:block1, false_target:block4
|
|
|
|
block4:
|
|
[ d0] End value:reg5
|
|
|
|
block5:
|
|
[ d8] GetGlobal dst:reg8, `depth`
|
|
[ f0] Add dst:reg7, lhs:reg8, rhs:Int32(2)
|
|
[ 100] SetGlobal `depth`, src:reg7
|
|
|
|
block6:
|
|
[ 118] GetGlobal dst:reg7, `depth`
|
|
[ 130] JumpLessThanEquals lhs:reg7, rhs:Int32(0), true_target:block5, false_target:block7
|
|
|
|
block7:
|
|
[ 148] Mov dst:reg5, src:reg6
|
|
[ 158] Jump target:block2
|