8000 vm: keep locals local (5% speedup) · go-python/gpython@00ffff0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 00ffff0

Browse files
committed
vm: keep locals local (5% speedup)
1 parent cf0f887 commit 00ffff0

File tree

3 files changed

+14
-34
lines changed

3 files changed

+14
-34
lines changed

notes.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Speed 35% improvement
1313
Before 2430 pystone/s
1414
After 3278 pystone/s
1515

16+
After compile debug out with a constant 9293 pystones/s + 180%
17+
Keep locals 9789 local 5% improvement
18+
19+
1620
Still to do
1721
* think about exception handling - do nested tracebacks work?
1822
* write a test for it!
@@ -24,7 +28,7 @@ CAN now inline the do_XXX functions into the EvalFrame which will probably speed
2428
* also make vm.STACK into frame.STACK and keep a pointer to frame
2529
* probably makes vm struct redundant? move its contents as locals.
2630
* move frame into vm module? Then can't use *Frame in
27-
31+
* tried this - was 20% slower
2832

2933
* Write go module
3034
* "go" command which is go(fn, args, kwargs) - implement with a builtin special in the interpreter probably

vm/eval.go

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,22 +1707,9 @@ func (vm *Vm) UnwindExceptHandler(frame *py.Frame, block *py.TryBlock) {
17071707
//
17081708
// This is the equivalent of PyEval_EvalFrame
17091709
func RunFrame(frame *py.Frame) (res py.Object, err error) {
1710-
vm := NewVm(frame)
1711-
// defer func() {
1712-
// if r := recover(); r != nil {
1713-
// switch x := r.(type) {
1714-
// case error:
1715-
// err = x
1716-
// case string:
1717-
// err = errors.New(x)
1718-
// default:
1719-
// err = errors.New(fmt.Sprintf("Unknown error '%s'", x))
1720-
// }
1721-
// if debugging { debugf("*** Exception raised %v\n", r) }
1722-
// // Dump the goroutine stack
1723-
// debug.PrintStack()
1724-
// }
1725-
// }()
1710+
var vm = Vm{
1711+
frame: frame,
1712+
}
17261713

17271714
// FIXME
17281715
// if (co->co_flags & CO_GENERATOR) {
@@ -1742,12 +1729,11 @@ func RunFrame(frame *py.Frame) (res py.Object, err error) {
17421729

17431730
var opcode OpCode
17441731
var arg int32
1732+
opcodes := frame.Code.Code
17451733
for vm.why == whyNot {
1746-
frame := vm.frame
17471734
if debugging {
17481735
debugf("* %4d:", frame.Lasti)
17491736
}
1750-
opcodes := frame.Code.Code
17511737
opcode = OpCode(opcodes[frame.Lasti])
17521738
frame.Lasti++
17531739
if opcode.HAS_ARG() {
@@ -1767,7 +1753,7 @@ func RunFrame(frame *py.Frame) (res py.Object, err error) {
17671753
}
17681754
}
17691755
vm.extended = false
1770-
err = jumpTable[opcode](vm, arg)
1756+
err = jumpTable[opcode](&vm, arg)
17711757
if err != nil {
17721758
// FIXME shouldn't be doing this - just use err?
17731759
if errExcInfo, ok := err.(py.ExceptionInfo); ok {
@@ -1778,11 +1764,9 @@ func RunFrame(frame *py.Frame) (res py.Object, err error) {
17781764
vm.SetException(py.MakeException(err))
17791765
}
17801766
}
1781-
if vm.frame != nil {
1782-
if debugging {
1783-
debugf("* Stack = %#v\n", vm.frame.Stack)
1784-
}
1785-
// if len(vm.frame.Stack) > 0 {
1767+
if debugging {
1768+
debugf("* Stack = %#v\n", frame.Stack)
1769+
// if len(frame.Stack) > 0 {
17861770
// if t, ok := vm.TOP().(*py.Type); ok {
17871771
// if debugging { debugf(" * TOP = %#v\n", t) }
17881772
// }
@@ -1794,9 +1778,8 @@ func RunFrame(frame *py.Frame) (res py.Object, err error) {
17941778

17951779
// Something exceptional has happened - unwind the block stack
17961780
// and find out what
1797-
for vm.why != whyNot && vm.frame.Block != nil {
1781+
for vm.why != whyNot && frame.Block != nil {
17981782
// Peek at the current block.
1799-
frame := vm.frame
18001783
b := frame.Block
18011784
if debugging {
18021785
debugf("*** Unwinding %#v vm %#v\n", b, vm)

vm/vm.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,3 @@ type Vm struct {
3838
// Previous exception type, value and traceback
3939
exc py.ExceptionInfo
4040
}
41-
42-
// Make a new VM
43-
func NewVm(frame *py.Frame) *Vm {
44-
return &Vm{
45-
frame: frame,
46-
}
47-
}

0 commit comments

Comments
 (0)
0