Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

json: Fast path for string encoding#133239

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
nineteendo wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
fromnineteendo:speedup-json-encode

Conversation

nineteendo
Copy link
Contributor

@nineteendonineteendo commentedMay 1, 2025
edited
Loading

pyperformance (with--enable-optimizations and--with-lto)

main.json=========Performance version: 1.11.0Python version: 3.15.0a0 (64-bit) revision fe9f6e829aReport on macOS-13.7.6-x86_64-i386-64bit-Mach-ONumber of logical CPUs: 8Start date: 2025-05-15 08:56:50.561560End date: 2025-05-15 08:57:59.544685feature.json============Performance version: 1.11.0Python version: 3.15.0a0 (64-bit) revision 32eefb3ef2Report on macOS-13.7.6-x86_64-i386-64bit-Mach-ONumber of logical CPUs: 8Start date: 2025-05-15 08:54:12.863957End date: 2025-05-15 08:55:18.964946### json_dumps ###Mean +- std dev: 12.3 ms +- 0.2 ms -> 10.4 ms +- 0.2 ms: 1.19x fasterSignificant (t=68.04)

jsonyx-performance-tests (with--enable-optimizations and--with-lto)

encodemainfeatureimprovement
Dict with 65,536 booleans9913.14 μs5937.37 μs1.67x faster
List of 65,536 ASCII strings12921.10 μs6773.93 μs1.91x faster
List of 65,536 strings86405.36 μs114756.66 μs1.33x slower

@methane
Copy link
Member

methane commentedMay 1, 2025
edited
Loading

https://gist.github.com/methane/e080ec9783db2a313f40a2b9e1837e72

Benchmarkmain#133186#133239
json_dumps: List of 256 booleans16.6 usnot significant17.2 us: 1.03x slower
json_dumps: List of 256 ASCII strings67.9 us34.7 us: 1.96x faster46.5 us: 1.46x faster
json_dumps: List of 256 dicts with 1 int122 us101 us: 1.21x faster112 us: 1.09x faster
json_dumps: Medium complex object205 us173 us: 1.18x faster189 us: 1.09x faster
json_dumps: List of 256 strings330 us302 us: 1.09x faster298 us: 1.11x faster
json_dumps: Complex object2.57 ms1.96 ms: 1.31x fasternot significant
json_dumps: Dict with 256 lists of 256 dicts with 1 int30.5 ms26.5 ms: 1.15x faster29.4 ms: 1.04x faster
json_dumps(ensure_ascii=False): List of 256 booleans16.6 usnot significant17.2 us: 1.03x slower
json_dumps(ensure_ascii=False): List of 256 ASCII strings68.1 us34.6 us: 1.96x faster46.5 us: 1.46x faster
json_dumps(ensure_ascii=False): List of 256 dicts with 1 int122 us101 us: 1.21x faster112 us: 1.09x faster
json_dumps(ensure_ascii=False): Medium complex object205 us172 us: 1.19x faster188 us: 1.09x faster
json_dumps(ensure_ascii=False): List of 256 strings329 us303 us: 1.09x faster298 us: 1.11x faster
json_dumps(ensure_ascii=False): Complex object2.56 ms1.95 ms: 1.31x fasternot significant
json_dumps(ensure_ascii=False): Dict with 256 lists of 256 dicts with 1 int30.6 ms26.5 ms: 1.15x faster29.4 ms: 1.04x faster
json_loads: List of 256 floats91.4 us88.3 us: 1.03x fasternot significant
json_loads: List of 256 strings848 us816 us: 1.04x fasternot significant
Geometric mean(ref)1.13x faster1.05x faster

Benchmark hidden because not significant (10): json_dumps: List of 256 floats, json_dumps(ensure_ascii=False): List of 256 floats, json_loads: List of 256 booleans, json_loads: List of 256 ASCII strings, json_loads: List of 256 dicts with 1 int, json_loads: Medium complex object, json_loads: Complex object, json_loads: Dict with 256 lists of 256 dicts with 1 int, json_loads: List of 256 stringsensure_ascii=False, json_loads: Complex objectensure_ascii=False

nineteendo reacted with thumbs up emoji

@nineteendo
Copy link
ContributorAuthor

@mdboom do you have the results of the Faster CPython infrastructure?

@mdboom
Copy link
Contributor

@mdboom do you have the results of the Faster CPython infrastructure?

Sorry, forgot to come back to them.

They are here:https://github.com/faster-cpython/benchmarking-public/blob/main/results/bm-20250501-3.14.0a7%2B-930e938/bm-20250501-linux-x86_64-nineteendo-speedup_json_encode-3.14.0a7%2B-930e938-vs-base.svg

Confirmed 14% faster on json_dumps benchmark. In the noise for the others (as one would expect).

nineteendo reacted with thumbs up emoji

@nineteendonineteendo marked this pull request as ready for reviewMay 13, 2025 14:06
{
/* Return the JSON representation of a string */
PyObject *encoded;

if (s->fast_encode) {
return s->fast_encode(NULL, obj);
if (PyUnicodeWriter_WriteChar(writer, '"') < 0) {
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We want to avoid this call for the normal path.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@nineteendo@methane@mdboom

[8]ページ先頭

©2009-2025 Movatter.jp