Repository navigation
perf(reflect): read struct fields and check assignability cheaply - #543
Merged
Merged
Conversation
Value.Field made a whole StructField, copying its index slice, only to read the field's type; for a StructType it now reads the type and the storage key of the field directly. typeAssignableTo built and compared the identity keys of the two types even when they were the same type, as they are for most Value.Set calls; a type is now assignable to itself without them. Signed-off-by: Randall C. O'Reilly <oreilly@ucdavis.edu>
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 free
to 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.
Two costs that showed up in profiles of a reflect-heavy program (a Go interpreter that reads and writes struct fields through reflect):
Value.Field built a complete StructField for the field, copying its Index slice, only to read the field's Type. For a StructType it now reads the field's type and storage key straight from the type's descriptors (a new StructType.fieldType alongside fieldKey); other struct types keep the old path.
typeAssignableTo computed and compared the identity keys of both types, which walks and stringifies them, even when the two were the same Type object, as they are for most Value.Set calls. It now returns true for identical types before building any key.
In the interpreter's struct method benchmark these took about 15% off (2.23 s to 1.91 s). The reflect unit tests and the reflect, struct, json and assignment compliance tests pass.