| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Currently in the main branch, there are 87 calls to PyBytesWriter_Create(). Only 15 resize the writer later:
I ran benchmarks on the following code to measure the PyBytesWriter overhead over PyBytes_FromStringAndSize(NULL, size).
I didn't find any obvious way to optimize PyBytesWriter.
Benchmark on:
const Py_ssize_t size = 3;
PyBytesWriter *writer = PyBytesWriter_Create(size);
if (writer == NULL) {
return NULL;
}
char *str = PyBytesWriter_GetData(writer);
memset(str, 'x', size);
return PyBytesWriter_Finish(writer);I tried to add a freelist to bytes for sizes in range [0; 255] (bytes): see draft PR #158657.
Benchmark with size=3 bytes:
Benchmark with size=64 bytes:
Benchmark with size=255 bytes:
Benchmark with size=300 bytes (don't use writer small buffer):
Notes:
I ran #158665 benchmark (create the string b'abc') to compare the 3.15 branch and the (current) main branches:
Mean +- std dev: [py315] 41.6 ns +- 1.0 ns -> [main] 32.5 ns +- 0.6 ns: 1.28x faster
Oh nice, the PyBytesWriter overhead is now way smaller on the main branch! The main branch is 9.1 ns faster.
I wrote an article on this work (and PyUnicodeWriter work): https://vstinner.github.io/optimize-pybyteswriter-pyunicodewriter-implementation.html.
| Back | FazBrowse Home | New Git URL |
Placeholder issue to keep track of changes to rework and enhance the PyBytesWriter implementation.
Linked PRs