vm: optimize stack traversal on exception handling

Before:
BenchmarkOpcodes/THROW/0/1-8       10000               506 ns/op
BenchmarkOpcodes/THROW/0/16-8      10000               524 ns/op
BenchmarkOpcodes/THROW/255/0-8     10000             49363 ns/op
BenchmarkOpcodes/THROW/1023/0-8                    10000           1628480 ns/op

After:
BenchmarkOpcodes/THROW/0/1-8       10000               575 ns/op
BenchmarkOpcodes/THROW/0/16-8      10000               516 ns/op
BenchmarkOpcodes/THROW/255/0-8     10000              8290 ns/op
BenchmarkOpcodes/THROW/1023/0-8                    10000             34605 ns/op
This commit is contained in:
Roman Khimov 2020-10-15 16:12:03 +03:00
parent 3d8434a50c
commit 27a01c7759

View file

@ -1521,7 +1521,8 @@ func (v *VM) calcJumpOffset(ctx *Context, parameter []byte) (int, int, error) {
func (v *VM) handleException() {
pop := 0
ictx := v.istack.Peek(0).Value().(*Context)
ictxv := v.istack.Peek(0)
ictx := ictxv.Value().(*Context)
for ictx != nil {
e := ictx.tryStack.Peek(0)
for e != nil {
@ -1547,7 +1548,8 @@ func (v *VM) handleException() {
return
}
pop++
ictx = v.istack.Peek(pop).Value().(*Context)
ictxv = ictxv.Next()
ictx = ictxv.Value().(*Context)
}
}