-
-
Notifications
You must be signed in to change notification settings - Fork 463
Improve the performance of runtime.Fetch for structures #833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
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)
2571efd to
01b16d4
Compare
|
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 |
| if value.IsValid() { | ||
| return value.Interface() | ||
| if ok { | ||
| value := v.FieldByIndex(field.Index) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need field.Index, can we just store that in the map instead of storing all the *reflect.StructField?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I've pushed a new commit to fix that (0fa18af)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
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.