Drop extra type check in _extract_serialize
#4281
Merged
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.
Currently
_extract_serialize
performs atype
check on its arguments and then when walking through any collections it performstype
checks on any values it encounters. If any of those values are collections, it effectively performs the sametype
check twice. Thus for more deeply nested structures, these additionaltype
checks will add up for every layer. To fix this, we perform atype
check on the arguments provided toextract_serialize
and do a bit of preparation on the arguments to_extract_serialize
. Additionally when looping over values in_extract_serialize
, we leverage this onetype
check to do any other preparation we may need to do with that info. As a result we are able to eliminate this overhead.Here's a rough benchmark showing the effect of this change:
Before:
After: