Improve union encoding performance #194
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, we have to wrap
int
andfloat
values on serialization withint(...)
andfloat(...)
. This is used as a hack for poor union serialization logic which is based on applying an encoding operation for each type in the list until we get the first result without errors. If we have a value of typeUnion[int, DataClassA]
then without applyingint(value)
(which will obviously fail on instances ofDataClassA
) we would pass instances ofDataClassA
as is becauseint
is on the first place.In this PR union serialization logic is changed so that we check the type of a value with pass-through strategy before returning it as is. It allows us to remove a hack for
int
andfloat
and not try to perform encoding operations that are known to fail.This pull request fixes the following issues: