-
Notifications
You must be signed in to change notification settings - Fork 46
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
Fast str and bytes builders #1036
Labels
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Right now there is no particularly fast way to construct a
str
orbytes
object from component items, such as code points or characters. Using a list +join()
, orStringIO
are probably not fast enough. These are common things to do in libraries and low-level code.We could add native
str
andbytes
builder classes that could be quite fast. Hypothetical example withbytes
:Here are some ideas about how to make this fast:
BytesBuilder
objects, so we usually wouldn't need to allocate it from the heap (or somehow stack allocate it).bytes
objects (which is likely very common). Allocate a larger buffer only when needed.append()
andextend()
calls, since we can assume these to be performance-critical.We can have a similar builder class for
str
objects, but it needs to also keep track of how many bytes per character we need. Possibly it would support giving a hint about the maximum code point value at construction. This might resemble_PyUnicodeWriter
, which is used in CPython.The text was updated successfully, but these errors were encountered: