[Python] - Improve Model Deserialization Perf - #11705
[Python] - Improve Model Deserialization Perf#11705Kashif Khan (kashifkhan) wants to merge 4 commits into
Conversation
commit: |
|
❌ There is undocummented changes. Run The following packages have changes but are not documented.
Show changes |
Python emitter diffBaseline Diff summary: 204 file(s), +29988 / -1836 Rendered diff: inline on the run summary, or the emitter-diff-html artifact. Informational check (eng/emitter-diff); does not block the PR. |
|
You can try these changes here
|
| dict_to_pass.update( | ||
| {k: _create_value(_get_rest_field(self._attr_to_rest_field, k), v) for k, v in args[0].items()} | ||
| { | ||
| k: create_value(rest_field_by_rest_name.get(k), v) |
There was a problem hiding this comment.
just to double click, are we sure that rest_field_by_rest_name.get(k) has the same fallback path for _get_rest_field(self._attr_to_rest_field, k) with keys that aren't rest names?
There was a problem hiding this comment.
yes pretty sure that is the case ( are there any tests/edge case etc I can use to further confirm ? )
right now in main we have
{k: _create_value(_get_rest_field(self._attr_to_rest_field, k), v) for k, v in args[0].items()}and _get_rest_field is:
try:
return next(rf for rf in attr_to_rest_field.values() if rf._rest_name == rest_name)
except StopIteration:
return NoneSame dict ( attr_to_rest_field.values() ), same key ( rf._rest_name ), right after _rest_name is finalized — so .get(k) returns the identical _RestField for a match and None for a non-rest-name key
| def _deserialize(cls, data, exist_discriminators): | ||
| if not hasattr(cls, "__mapping__"): | ||
| return cls(data) | ||
| return cls(data) if isinstance(data, ET.Element) else cls(_OwnedWireValue(data)) |
There was a problem hiding this comment.
nit: maybe combine these two cls(data) if ... else ... into one function / variable definition
d85b447 to
5227b40
Compare
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
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)