Skip to content

[Python] - Improve Model Deserialization Perf - #11704

Closed
Kashif Khan (kashifkhan) wants to merge 2 commits into
microsoft:mainfrom
kashifkhan:deserialization_perf
Closed

[Python] - Improve Model Deserialization Perf#11704
Kashif Khan (kashifkhan) wants to merge 2 commits into
microsoft:mainfrom
kashifkhan:deserialization_perf

Conversation

@kashifkhan

Copy link
Copy Markdown
Member

This PR focusses on improving the performance of the deserialization path of python generated files. I wanted to focus on a couple areas where speed ups could be done and see some results

  • Do less work :) - today, when a model is built from a parsed payload, every value was sent to _serialize. Things like int, float, list[str] don't need to be serialized. Store them as is and work on things that need it
  • Look things up once, not every time — we compute two things one time per model class: a rest_name2field map, and the small list of fields that have client defaults. That way building each object skips re-scanning all the fields
  • Annotation Cache - figuring out how to deserialize a field (e.g.  List[Pet],  Optional[datetime]) means walking typing internals, and the answer never changes for a given type, so it's cached.

On a ~5.6 MB DocumentIntelligence-shaped (why I started this) response on Python 3.10:

• Building the model tree: ~2.7× faster (~880 ms dropped to ~330 ms)
• Build + read every field: roughly halved (~2.0 s dropped to ~1.15 s)

@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Aug 17, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-python@11704

commit: d85b447

@github-actions

Copy link
Copy Markdown
Contributor

❌ There is undocummented changes. Run chronus add to add a changeset or click here.

The following packages have changes but are not documented.

  • @typespec/http-client-python
Show changes

@azure-sdk-automation

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@kashifkhan

Copy link
Copy Markdown
Member Author

new branch here #11705

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

Labels

emitter:client:python Issue for the Python client emitter: @typespec/http-client-python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant