Skip to content

Improve lexer performance using struct-array#64

Open
msujew wants to merge 1 commit intomainfrom
msujew/use-token-struct-array
Open

Improve lexer performance using struct-array#64
msujew wants to merge 1 commit intomainfrom
msujew/use-token-struct-array

Conversation

@msujew
Copy link
Copy Markdown
Member

@msujew msujew commented Apr 25, 2026

Performs some minor and a major performance optimizations:

  1. (major) The TokenSlice uses the Token struct directly instead of using a pointer. This improves lexing performance by ~40%
  2. (minor) Adds a running tokens-per-byte average to the lexer. This ensures (1) that we rarely try to increase the slice capacity and (2) keep the capacity as low as possible. Improves performance by ~3%.
  3. (minor) changes the lookup from slices.IndexFunc to a custom loop. Does not influence performance - it seems like the Go compiler was able to inline the function call. However, this still makes everything easier to read.
  4. (minor) Do not put the utf8 conversion behind a conditional. Improves performance by 3%.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant