Skip to content
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

v.scanner: use table lookups for very frequently done character checks #21931

Merged

Conversation

spytheman
Copy link
Member

@spytheman spytheman commented Jul 25, 2024

This has only the lookup changes from #21545 .
The substr_unsafe commit, turned out to be a problem.

  • v.scanner: use precomputed character tables instead of checks
  • v.scanner: use util.func_char_table in Scanner.ident_name/0
  • v.scanner: restore the checks in ident_name, instead of using util.func_char_table
  • v.scanner: split long condition in ident_name into several smaller ones
  • v.scanner: use substr_unsafe in Scanner.ident_name/0 and Scanner.num_lit/2
  • Revert "v.scanner: use substr_unsafe in Scanner.ident_name/0 and Scanner.num_lit/2"
  • v.scanner: move non_whitespace_table to v.util
  • v.scanner: use util.func_char_table[c] and util.name_char_table[c] directly
  • v.util: cleanup the table generating functions, by using the builtin u8 methods

@spytheman spytheman changed the title scanner use tables instead of checks v.scanner: use table lookups for very frequently done character checks Jul 25, 2024
@spytheman
Copy link
Member Author

With clang:
image

@spytheman
Copy link
Member Author

spytheman commented Jul 25, 2024

With gcc, the speedup is very modest (under 1%), and sometimes (rarely), the old version is slightly faster (i.e. it is on the margin for error on my machine).

With tcc, the speedup is consistently around 1-2% for the scanner.

@spytheman spytheman merged commit 97432c3 into vlang:master Jul 25, 2024
73 checks passed
@felipensp
Copy link
Member

Nice, good job!

@spytheman spytheman deleted the scanner_use_tables_instead_of_checks branch July 25, 2024 16:28
@medvednikov
Copy link
Member

Great job! Hyperfine reports ~4% though, not 1-2%?

@JalonSolov
Copy link
Contributor

Probably dependent on the hardware where you run it. CPU speed, memory speed, etc. can all affect code running speed.

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.

4 participants