Skip to content

feat: Enhance JSON serialization with improved orjson integration#20181

Closed
xingarr wants to merge 2 commits into
python:masterfrom
xingarr:feature/enhance-json-serialization-performance
Closed

feat: Enhance JSON serialization with improved orjson integration#20181
xingarr wants to merge 2 commits into
python:masterfrom
xingarr:feature/enhance-json-serialization-performance

Conversation

@xingarr

@xingarr xingarr commented Nov 4, 2025

Copy link
Copy Markdown
  • 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.

(Explain how this PR changes mypy.)

xingarr and others added 2 commits November 4, 2025 15:20
- 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.
@github-actions

github-actions Bot commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JukkaL

JukkaL commented Nov 4, 2025

Copy link
Copy Markdown
Collaborator

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 --fixed-format-cache, but we are planning to make it the default (and eventually only) format within the next few releases. Unfortunately, it seems that this is not something that we need.

@hauntsaninja hauntsaninja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@xingarr

xingarr commented Nov 4, 2025

Copy link
Copy Markdown
Author

THanks for your review, so what you want me to update in this PR?

@hauntsaninja hauntsaninja added the pending Issues that may be closed label Nov 8, 2025
@A5rocks

A5rocks commented Nov 20, 2025

Copy link
Copy Markdown
Collaborator

@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?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending Issues that may be closed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants