Improve encoding performance for empty interface type

This commit is contained in:
Masaaki Goshima 2021-06-26 15:49:13 +09:00
parent 595e20a25e
commit 66bf979e47
5 changed files with 45 additions and 20 deletions

View File

@ -177,9 +177,11 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
code = code.Next code = code.Next
break break
} }
for _, seen := range ctx.SeenPtr { if recursiveLevel > encoder.StartDetectingCyclesAfter {
if p == seen { for _, seen := range ctx.SeenPtr {
return nil, errUnsupportedValue(code, p) if p == seen {
return nil, errUnsupportedValue(code, p)
}
} }
} }
ctx.SeenPtr = append(ctx.SeenPtr, p) ctx.SeenPtr = append(ctx.SeenPtr, p)
@ -226,9 +228,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next))) store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
storeIndent(ctxptr, end, uintptr(oldBaseIndent)) storeIndent(ctxptr, end, uintptr(oldBaseIndent))
code = c code = c
recursiveLevel++
case encoder.OpInterfaceEnd: case encoder.OpInterfaceEnd:
offset := load(ctxptr, code.Idx) recursiveLevel--
// restore ctxptr // restore ctxptr
offset := load(ctxptr, code.Idx)
restoreIndent(ctx, code, ctxptr) restoreIndent(ctx, code, ctxptr)
ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1] ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1]

View File

@ -177,9 +177,11 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
code = code.Next code = code.Next
break break
} }
for _, seen := range ctx.SeenPtr { if recursiveLevel > encoder.StartDetectingCyclesAfter {
if p == seen { for _, seen := range ctx.SeenPtr {
return nil, errUnsupportedValue(code, p) if p == seen {
return nil, errUnsupportedValue(code, p)
}
} }
} }
ctx.SeenPtr = append(ctx.SeenPtr, p) ctx.SeenPtr = append(ctx.SeenPtr, p)
@ -226,9 +228,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next))) store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
storeIndent(ctxptr, end, uintptr(oldBaseIndent)) storeIndent(ctxptr, end, uintptr(oldBaseIndent))
code = c code = c
recursiveLevel++
case encoder.OpInterfaceEnd: case encoder.OpInterfaceEnd:
offset := load(ctxptr, code.Idx) recursiveLevel--
// restore ctxptr // restore ctxptr
offset := load(ctxptr, code.Idx)
restoreIndent(ctx, code, ctxptr) restoreIndent(ctx, code, ctxptr)
ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1] ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1]

View File

@ -177,9 +177,11 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
code = code.Next code = code.Next
break break
} }
for _, seen := range ctx.SeenPtr { if recursiveLevel > encoder.StartDetectingCyclesAfter {
if p == seen { for _, seen := range ctx.SeenPtr {
return nil, errUnsupportedValue(code, p) if p == seen {
return nil, errUnsupportedValue(code, p)
}
} }
} }
ctx.SeenPtr = append(ctx.SeenPtr, p) ctx.SeenPtr = append(ctx.SeenPtr, p)
@ -226,9 +228,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next))) store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
storeIndent(ctxptr, end, uintptr(oldBaseIndent)) storeIndent(ctxptr, end, uintptr(oldBaseIndent))
code = c code = c
recursiveLevel++
case encoder.OpInterfaceEnd: case encoder.OpInterfaceEnd:
offset := load(ctxptr, code.Idx) recursiveLevel--
// restore ctxptr // restore ctxptr
offset := load(ctxptr, code.Idx)
restoreIndent(ctx, code, ctxptr) restoreIndent(ctx, code, ctxptr)
ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1] ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1]

View File

@ -177,9 +177,11 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
code = code.Next code = code.Next
break break
} }
for _, seen := range ctx.SeenPtr { if recursiveLevel > encoder.StartDetectingCyclesAfter {
if p == seen { for _, seen := range ctx.SeenPtr {
return nil, errUnsupportedValue(code, p) if p == seen {
return nil, errUnsupportedValue(code, p)
}
} }
} }
ctx.SeenPtr = append(ctx.SeenPtr, p) ctx.SeenPtr = append(ctx.SeenPtr, p)
@ -226,9 +228,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next))) store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
storeIndent(ctxptr, end, uintptr(oldBaseIndent)) storeIndent(ctxptr, end, uintptr(oldBaseIndent))
code = c code = c
recursiveLevel++
case encoder.OpInterfaceEnd: case encoder.OpInterfaceEnd:
offset := load(ctxptr, code.Idx) recursiveLevel--
// restore ctxptr // restore ctxptr
offset := load(ctxptr, code.Idx)
restoreIndent(ctx, code, ctxptr) restoreIndent(ctx, code, ctxptr)
ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1] ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1]

View File

@ -177,9 +177,11 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
code = code.Next code = code.Next
break break
} }
for _, seen := range ctx.SeenPtr { if recursiveLevel > encoder.StartDetectingCyclesAfter {
if p == seen { for _, seen := range ctx.SeenPtr {
return nil, errUnsupportedValue(code, p) if p == seen {
return nil, errUnsupportedValue(code, p)
}
} }
} }
ctx.SeenPtr = append(ctx.SeenPtr, p) ctx.SeenPtr = append(ctx.SeenPtr, p)
@ -226,9 +228,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next))) store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
storeIndent(ctxptr, end, uintptr(oldBaseIndent)) storeIndent(ctxptr, end, uintptr(oldBaseIndent))
code = c code = c
recursiveLevel++
case encoder.OpInterfaceEnd: case encoder.OpInterfaceEnd:
offset := load(ctxptr, code.Idx) recursiveLevel--
// restore ctxptr // restore ctxptr
offset := load(ctxptr, code.Idx)
restoreIndent(ctx, code, ctxptr) restoreIndent(ctx, code, ctxptr)
ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1] ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1]