feat: Enhance JSON serialization with improved orjson integration#20181
feat: Enhance JSON serialization with improved orjson integration#20181xingarr wants to merge 2 commits into
Conversation
- Add robust error handling for orjson import and usage - Implement comprehensive fallback mechanism when orjson is unavailable - Add performance benchmarking utilities for JSON operations (mypy.json_bench) - Include comprehensive test suite with 18 tests for edge cases - Document performance characteristics and usage patterns - Improve error handling for large integers exceeding 64-bit range - Add detailed documentation explaining cache consistency requirements This enhancement improves the faster-cache feature reliability and provides better visibility into JSON serialization performance, which is critical for mypy's incremental type checking caching mechanisms. Resolves TODO items in mypy/util.py related to JSON optimization and sorted keys requirement documentation.
for more information, see https://pre-commit.ci
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
We are moving from JSON serialization to a binary serialization format with a separate tool to convert binary cache files to JSON. The new format is currently enabled using |
hauntsaninja
left a comment
There was a problem hiding this comment.
Thanks! This is a much larger diff than needed; if you are seeing an exception on load or dump, could you describe exactly what you are seeing? If so, open to a diff that only has the exception handling changes
|
THanks for your review, so what you want me to update in this PR? |
|
@xingarr (paraphrasing @hauntsaninja's review) Can you describe a test case which will cause mypy to cache something leading to an (eg) overflow? Or that would lead to orjson.loads erroring? Generally it seems like you're changing or adding code that doesn't need to be there, so justifying that would be appreciated. Like a built in json benchmark doesn't make sense, nor the new docs page. (I think we prominently advertise the faster cache extra?) |
This enhancement improves the faster-cache feature reliability and provides better visibility into JSON serialization performance, which is critical for mypy's incremental type checking caching mechanisms.
Resolves TODO items in mypy/util.py related to JSON optimization and sorted keys requirement documentation.
(Explain how this PR changes mypy.)