Skip to content

Conversation

@maurycy
Copy link
Contributor

@maurycy maurycy commented Sep 16, 2025

The change is very similar to #138956

Initially, I thought that there's a speed up, but I mixed the JSON files, and it's the reverse:

Benchmark json-main json-pybytes
json_loads_1000_ints 41.4 us 47.3 us: 1.14x slower
json_loads_1000_floats 77.1 us 81.9 us: 1.06x slower
Geometric mean (ref) 1.10x slower

which makes perfect sense given the conversion:

https://github.com/python/cpython/pull/138957/files#diff-efe183ae0b85e5b8d9bbbc588452dd4de80b39fd5c5174ee499ba554217a39edR1110

I mixed up the JSONs; my bad.

I'm surprised with the speed up:

Benchmark

The script:
import pyperf
import json

runner = pyperf.Runner()

num_elements = 1000

int_data = json.dumps(list(range(num_elements)))
runner.bench_func(f'json_loads_{num_elements}_ints', json.loads, int_data)

float_data = json.dumps([float(i) for i in range(num_elements)])
runner.bench_func(f'json_loads_{num_elements}_floats', json.loads, float_data)

Where main is 4e00e25

The environment:

% ./python -c "import sysconfig; print(sysconfig.get_config_var('CONFIG_ARGS'))"
'--enable-lto' '--with-optimizations'

sudo ./python -m pyperf system tune ensured.

@maurycy maurycy changed the title gh-129813: Use PyBytesWriter in _json:_match_number_unicode; json.loads with int or float 1.14x faster gh-129813: Use PyBytesWriter in _json:_match_number_unicode; json.loads with int or float ~1.1x faster Sep 16, 2025
@maurycy maurycy changed the title gh-129813: Use PyBytesWriter in _json:_match_number_unicode; json.loads with int or float ~1.1x faster gh-129813: Use PyBytesWriter in _json:_match_number_unicode Sep 16, 2025
@maurycy
Copy link
Contributor Author

maurycy commented Sep 16, 2025

I'm closing it. I don't think it's making things better.

@maurycy maurycy closed this Sep 16, 2025
@maurycy maurycy deleted the json-match-number-unicode-pybytes branch September 16, 2025 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant