gh-155742: Optimize json float parsing - #156897
Open
vstinner wants to merge 2 commits into
Open
Conversation
Similar to PyFloat_FromString(), but don't require a Python object. Use _PyFloat_FromString() in _json to avoid creating a temporary bytes objects. _Py_string_to_number_with_underscores() can now be called with NULL object and float_from_string_inner() can now be called with NULL data; if needed they create a temporary bytes objects to format the error message.
Member
Author
|
Benchmark: import pyperf
import json
import random
NUMBERS = 10 ** 4
ITEMS = [str(random.random()) for _ in range(NUMBERS)]
DATA = '[' + ', '.join(ITEMS) + ']'
runner = pyperf.Runner()
runner.bench_func('json.loads', json.loads, DATA)Result: |
Fix the compiler warning:
{'file': 'Objects/floatobject.c', 'line': '174', 'column': '5',
'message': 'label followed by a declaration is a C23 extension',
'option': '-Wc23-extensions'}
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add internal _PyFloat_FromString(): similar to PyFloat_FromString(),
but don't require a Python object.
Use _PyFloat_FromString() in _json to avoid creating a temporary bytes objects.
_Py_string_to_number_with_underscores() can now be called with NULL object and float_from_string_inner() can now be called with NULL data; if needed they create a temporary bytes objects to format the error message.