Uh oh!
There was an error while loading. Please reload this page.
Improve the performance of runtime.Fetch for structures - #833
Merged
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)
antonmedv
commented
Sep 16, 2025
Member
So is this only if no env is provided? What is a case of compiling without the knowing which env? |
montag451
commented
Sep 23, 2025
ContributorAuthor
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 |
antonmedv
self-requested a review
September 24, 2025 09:50
| if value.IsValid() { | ||
| return value.Interface() | ||
| if ok { | ||
| value := v.FieldByIndex(field.Index) |
Contributor
There was a problem hiding this comment.
We only need field.Index, can we just store that in the map instead of storing all the *reflect.StructField?
ContributorAuthor
There was a problem hiding this comment.
Good catch! I've pushed a new commit to fix that (0fa18af)
antonmedv
approved these changes
Dec 14, 2025
Uh oh!
There was an error while loading. Please reload this page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.