Repository navigation
Conversation
Improve the performance of tokenize.tokenize and tokenize.generate_tokens. This is primarily for improved FT scaling however non GIL also benefits too.
|
This does have some downsides if I think the alternative for this issue is to improve the scaling of |
|
Marking draft on reflection until there's some issue discussion! |
| try: | ||
| for info in it: | ||
| yield TokenInfo._make(info) | ||
| yield tuple.__new__(TokenInfo, info) |
There was a problem hiding this comment.
In general, I think we should aim to make pure-Python code scale well on the free-threaded build without changes. Is it possible to avoid refcount contention without relying on hacks like this (such as by using DRC in C code)?
There was a problem hiding this comment.
In general I think this comes to optimising closures in FT, if we were to make no python changes. Each closure cell requires a shared ref increment, and also nested functions are not enabled for deferred reference counting, resulting in another shared ref access. So yes essentially DRC is likely fix for those however likely some considerations to resolve these properly.
#148610 would also be required to speedup TokenInfo._make (with the above optimised) however a simple hoist would be sufficient with the closure optimisations, but that seems easier said then done due to the wider impact.
An alternative is to avoid the use of closures of the namedtuple._make and instead create it from module-level code, so it isn't a nested function. Currently I think this requires using exec to construct the _make function inside namedtuple() which does come with a slight performance penalty (of about 2%) for class construction.
Improve the performance of tokenize.tokenize
and tokenize.generate_tokens. This is primarily
for improved FT scaling however non GIL also benefits too.
tokenize.tokenizeandtokenize.generate_tokenson FT build #163220Micro benchmark
On macos m5 --enable-optimizations --with-lto