-
-
Notifications
You must be signed in to change notification settings - Fork 32k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
https://gist.github.com/methane/e080ec9783db2a313f40a2b9e1837e72
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 |
@mdboom do you have the results of the Faster CPython infrastructure? |
Sorry, forgot to come back to them. Confirmed 14% faster on json_dumps benchmark. In the noise for the others (as one would expect). |
{ | ||
/* Return the JSON representation of a string */ | ||
PyObject *encoded; | ||
|
||
if (s->fast_encode) { | ||
return s->fast_encode(NULL, obj); | ||
if (PyUnicodeWriter_WriteChar(writer, '"') < 0) { |
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.
We want to avoid this call for the normal path.
pyperformance (with
--enable-optimizations
and--with-lto
)jsonyx-performance-tests (with
--enable-optimizations
and--with-lto
)