Skip to content

Conversation

bonzini
Copy link
Collaborator

@bonzini bonzini commented Oct 17, 2025

Cut about 2/3 of the execution time of the lexer, and a little more elsewhere. Even on a project like QEMU that spends a lot of time in external scripts, this amounts to a 3-5% saving.

@bonzini bonzini marked this pull request as ready for review October 17, 2025 16:53
Match single-character tokens a separate dictionary lookup.
As pointed out by dcbaker, this is even faster than str.index
and gives the syntax error check for free (via KeyError).
It also enables splitting the special-case "if" in two parts, one
for long tokens and one for short tokens, thus providing further
speedup.

This shaves about 2/3rds of the time spent in lex().

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Identifiers are more common than strings, check against 'id'
first.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Tuples are inefficient, require the ability to use hash table lookup
via either a frozenset or a dictionary.

This also allows using accept_any with COMPARISON_MAP.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
…tor names

This avoids creating a dictionary every time an arithmetic operator
is evaluated.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants