nineteendo · GitHub

Feature or enhancement

Proposal:

Most JSON strings consist solely of ASCII characters that don’t require escaping, so adding a fast path for those would make a big difference. In these cases, we can avoid allocating a new string by writing the original string directly:

PyUnicodeWriter_WriteChar(writer, '"')
PyUnicodeWriter_WriteStr(writer, pystr) // original string
PyUnicodeWriter_WriteChar(writer, '"')

Benchmarks have shown that this roughly 2.2x faster, see PR.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Read the original on github.com ↗