added 24 commits
December 28, 2021 12:16Move all msgpack specific things out of the top-level namespace to `msgspec.msgpack`. This is in preparation for supporting other encodings like `json`.
Pulling character escaping out into a separate function lets clang optimize this routine further. Clang is ~40% faster than gcc for some benchmarks here, not sure why.
Implements the Eisel-Lemire algorithm for float parsing, based on the original implementation, Nigel Tao's blogpost, and the implementation in Wuffs. A fallback method still is needed for cases where Eisel-Lemire fails.
Closed
3 tasks
- Error if trailing characters are present in both JSON and msgpack decoders. - Fix a bug in utf-16 codepoint decoding After these changes, the JSON decoder fully passes the JSONTestSuite tests at https://github.com/nst/JSONTestSuite.
Track start, end, and position pointers instead of start + read index. This was already done in the JSON decoder (where a position pointer was a bit easier to work with), we know do this in the msgpack decoder as well.
We were using a mix of `js_`/`json_` and `mp_`/`mpack_` prefixes. Standardize on the longer prefixes.
- Remove need for `TypeNode_Repr` - we now rely on the builtin reprs - Add module name to decoder reprs
Previously we attempted to support serializing both naive and aware datetime objects. Since MsgPack timestamps are by nature "aware", we interpreted naive datetimes implicitly as representing local time. This assumption could be a footgun for unaware users, and so is removed. Only aware datetimes are supported. This commit also dramatically improves the performance of msgpack datetime encoding/decoding (which previously relied on calling into python methods to do the conversion). datetime <-> epoch conversion is now handled entirely within msgspec itself, resulting in ~10x speedup on encoding and ~5x speedup on decoding.
Previously for JSON datetimes with a timezone offset, we'd decode the datetime into the specified timezone. To avoid the cost of creating a new `datetime.timezone` object every time, we'd cache the most recent timezone to reuse it if possible. However, the msgpack decoder always decodes datetimes into UTC, and most users will probably want UTC anyway. To keep things compatible, we now always decode all datetimes into UTC for JSON, applying the offset as needed. An added perk is that this is much faster, as we don't ever hit Python method calls on decode.
Not all types are JSON compatible (e.g. dicts with non-str keys). We previously attempted to handle this, but it didn't cover all cases. We now improve this error handling, and add test cases for this behavior.