expr
expr copied to clipboard
Improve the performance of runtime.Fetch for structures
The improvement comes from the use of a cache to speed up the retrieval of struct fields. This commit also adds a new benchmark to measure the performance gain.
goos: linux
goarch: amd64
pkg: github.com/expr-lang/expr
cpu: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
│ /tmp/old.txt │ /tmp/new.txt │
│ sec/op │ sec/op vs base │
_envStruct_noEnv-8 503.3n ± 4% 228.8n ± 3% -54.53% (p=0.000 n=10)
│ /tmp/old.txt │ /tmp/new.txt │
│ B/op │ B/op vs base │
_envStruct_noEnv-8 48.00 ± 0% 32.00 ± 0% -33.33% (p=0.000 n=10)
│ /tmp/old.txt │ /tmp/new.txt │
│ allocs/op │ allocs/op vs base │
_envStruct_noEnv-8 3.000 ± 0% 1.000 ± 0% -66.67% (p=0.000 n=10)
So is this only if no env is provided? What is a case of compiling without the knowing which env?
No it's also when the field of a struct is an interface. I didn't pass an env in the test to be sure that OpFetch is used instead of OpLoadField