You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improving scaling for tokenize.tokenize and tokenize.generate_tokens on FT build #163220
TOKENIZE_SOURCE = '''\
def f(a, b=1, *args, c: int = 2, **kwargs):
"""Docstring."""
x = [i * 2 for i in range(10) if i % 3]
return {"a": a, "b": b, "x": x} # comment
'''
@register_benchmark
def tokenize_source():
for _ in range(10 * WORK_SCALE):
for _ in tokenize.generate_tokens(io.StringIO(TOKENIZE_SOURCE).readline):
pass
This seems to stem from constructing TokenInfo with TokenInfo._make which results in updating various shared reference counts. Directly constructing via tuple.__new__(TokenInfo, info) given TokenInfo is a subclass of a tuple results much better scaling and even faster for GIL builds too. Another option is to optimise the _make itself.
Improving the scaling would enable various introspection such as linters to better utilise threads on FT build.
changed the title [-]Improving scaling for `an` on FT build[/-][+]Improving scaling for `tokenize.tokenize` and `tokenize.generate_tokens` on FT build[/+]on Dec 5, 2026
Activity
[-]Improving scaling for `an` on FT build[/-][+]Improving scaling for `tokenize.tokenize` and `tokenize.generate_tokens` on FT build[/+]