GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-129813: Use `PyBytesWriter` in `_json:_match_number_unicode` by maurycy · Pull Request #138957 · python/cpython

Conversation

@maurycy

@maurycy maurycy commented Sep 16, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

  • Issue: [C API] PEP 782: Add PyBytesWriter API #129813

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@maurycy
use PyBytes in json:_match_number_unicode
190ca24
@bedevere-app bedevere-app Bot added the awaiting review label Sep 16, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Sep 16, 2025
[C API] PEP 782: Add PyBytesWriter API #129813
Closed
@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

maurycy commented Sep 16, 2025

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@maurycy
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.