Skip to content

refactor: improve pydantic json dump#2130

Merged
waketzheng merged 3 commits intotortoise:developfrom
waketzheng:improve-pydantic-json-dump
Mar 8, 2026
Merged

refactor: improve pydantic json dump#2130
waketzheng merged 3 commits intotortoise:developfrom
waketzheng:improve-pydantic-json-dump

Conversation

@waketzheng
Copy link
Contributor

Description

Currently JSONField use model_dump+JSON_DUMPS for pydantic model dumping, we can use model_dump_json to improve performance.

Motivation and Context

FastAPI say that Serialize JSON response with Pydantic results in 2x (or more) performance increase for JSON responses https://github.com/fastapi/fastapi/releases/tag/0.130.0

How Has This Been Tested?

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 1, 2026

Merging this PR will not alter performance

✅ 24 untouched benchmarks


Comparing waketzheng:improve-pydantic-json-dump (7027d1d) with develop (314273c)

Open in CodSpeed

@waketzheng waketzheng requested review from abondar and henadzit March 8, 2026 12:03
@waketzheng waketzheng merged commit 5e65d83 into tortoise:develop Mar 8, 2026
25 checks passed
@waketzheng waketzheng deleted the improve-pydantic-json-dump branch March 8, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants