added 8 commits
October 25, 2021 18:24Instead of having the outer loop of the typed decoder switch on the *expected* type, we revert back to switching on the *received* type. This slightly slows down untyped decoding with the benefit of reducing code size (both LOC and binary) by unifying the typed & untyped decoders. It also opens up the opportunity for handling `Union` types in the decoder.
Now typenodes are implemented via a bitset of type values & a variable length array of extra info. This makes it possible to express type unions in an efficient manner (though union types beyond `Optional` aren't yet implemented). This has no performance measurable performance impact compared with the main branch, but does reduce slightly the untyped decoding degradations introduced in the previous commit. The untyped decoder is still slower than it was previously (at most ~7% slower by my measurements), but typed decoding measures the same as the main branch, and can now support more features going forward.
This adds support to `msgspec.Decoder` for parsing type unions. Limitations within a single type `Union` include: - Multiple array-like types are not supported - Multiple dict types are not supported - IntEnum and int cannot coexist - Enum and str cannot coexist - Struct and dict (or Struct and array-like types, if `asarray=True`) cannot coexist - If a custom type is present, the only other type supported in the union is `None`.
A bunch of micro-optimizations to remove most of the performance degradation caused by this refactor. Perf is basically the same as before now. Also fixes a bug around unions containing both asarray structs and dicts.