-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-95385 Fastpath for encoding dict to JSON #95374
Conversation
4d40abf
to
e2929e7
Compare
The code is based on another PR (gh-95382) not merged yet just to avoid passing extra parameters around. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please separate the patch from removing indent_level params.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
When sorting of keys is not requsted and we are encoding a dict use PyDict_Next to iterate over keys and values. Leave the old path with PyMapping_Items that creates a list of key-value tuples for cases when sorting is requested. Don't use mapping items and iterator: we check and know we are using a dict and list.
6e92af6
to
9137b1b
Compare
I have made the requested changes; please review again |
Thanks for making the requested changes! @corona10: please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you like to provide a benchmark script and result for the following conditions?
- json.dumps when sorting of key is required
- json.dumps when sorting of key is not required (your suggestion)
This is without sorting of keys, the default behavior of json.dumps
pyperformance after changes:
|
With pyperformance sort_keys=True, I edited benchmarks/bm_json_dumps/run_benchmark.py for that before changes
after changes (PyList_GET_ITEM is a bit faster than PyIter_Next?)
|
@aivarsk Thank you, I will take a look at this PR through this weekend :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, I should check several possibilities of regression including leaks but not found :)
Overall looks good LGTM, but please follow PEP 7 if possible.
I just left nit comments :)
Co-authored-by: Dong-hee Na <[email protected]>
Co-authored-by: Dong-hee Na <[email protected]>
Co-authored-by: Dong-hee Na <[email protected]>
Co-authored-by: Dong-hee Na <[email protected]>
When sorting of keys is not requested and we are encoding a dict
use PyDict_Next to iterate over keys and values.
When sorting is requested use PyList_GET_ITEM instead of PyIter_Next because we know we are working with a list.