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-118299: Re-use old indent in json.loads()
#118300
Conversation
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.
This seems like too complex of a change, unless the performance impact justifies a more thorough code review. Have you measured the performance improvement?
And why rename the function parameter names? That's not making this easier to review. Renaming does not seem important. At best it should be a separate commit, although I doubt it's worth doing.
Yes, see the description of the pull request. If there are other cases you would like me to benchmark, let me know.
We're no longer passing the indent level, we're passing the newline indent now. I can keep the names, but it'll make the code more confusing for future readers. |
The difference is so small that it does not worth a NEWS entry. In most cases there is no visible difference. I did not not expect significal difference, algorithmically it has the same complexity, and computing the indentation string has minor contribution in the total time. I proposed this approach for the C code because it may simplify it, and the saving in computing the indentation for the closing bracket may have larger impact. It is less important in Python. I would wait with until we finish with C implementation. If it will end with this approach, it will be a small argument of using it in the Python implementation too. |
Can we use it for the Python implementation now #118105 is merged? |
Do you mean we will also be able to use caching in Python with improved performance? Aren't strings always copied when passed around? |
I have doubts. Even this PR is too complicated for such small gain (taking into account that normally the C implementation is used). More complex caching scheme increases the cost. On other hand, the complicated C code can be translated to simple Python code, and the benefit/ratio cost can be very good. We cannot say until we try.
Objects are never copied when passed as arguments in Python. And strings are never copied, they are immutable. |
OK, I'll close it then, or did I misunderstand you? |
Benchmark
macOS
script
Windows
script
json.loads()
#118299