-
-
Notifications
You must be signed in to change notification settings - Fork 485
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
Fast path for parsing decimal literals #3288
Comments
As I mentioned in #3289, it's mysterious why #3283 got a 5% speed bump on lexer benchmarks. Before we test out what I'm suggesting in this issue, we should investigate that further. If it turns out that converting the padding bytes in |
Just did something similar for non-decimals in #3296. Decimals are up next |
@overlookmotel I discovered that |
Is this resolved? |
I don't believe so.
@DonIsaac Did you try parsing to a |
I did, but I saw no performance gains. |
Did you try implementing it manually like If you're in |
I gave it a go (#4257). Yes, hardly any effect. Surprising! |
Closes #3288. Speed up parsing decimal literals (e.g. `123`), using same techniques as `parse_octal` etc.
Closes #3288. Speed up parsing decimal literals (e.g. `123`), using same techniques as `parse_octal` etc.
Closes #3288. Speed up parsing decimal literals (e.g. `123`), using same techniques as `parse_octal` etc.
Closes #3288. Speed up parsing decimal literals (e.g. `123`), using same techniques as `parse_octal` etc.
Closes #3288. Speed up parsing decimal literals (e.g. `123`), using same techniques as `parse_octal` etc.
@DonIsaac I'm frustrated how little effect this change had, though it in retrospect it makes sense - multiplying by 10 is just inherently a (relatively) slow operation. Why oh why don't humans have 8 fingers and then decimal would never have existed? 😃 Do you think there'd be any gain in adding a token kind for single digit number, with a fast path? |
#3283 made an optimization to the parser to avoid checking for
_
s in numeric literals twice, and got a nice 1% speed-up on parser benchmarks.It occurs to me that we could repeat the trick for the common case of simple decimal literals (e.g.
0
,1
,123
).str::parse::<f64>()
is quite a complicated function which checks for all kinds of things (exponent, decimal point, valid input etc). All of this is repeated work, since we've already determined in the lexer what the input is.Perhaps we could have a flag which lexer sets if the input is a simple case, and then use a hand-rolled
parse_simple_decimal
function to convert tof64
, like the ones we have for binary and octal?oxc/crates/oxc_parser/src/lexer/number.rs
Lines 76 to 88 in f38d138
(we should base implementation on
std
'sstr::parse::<f64>
as it's probably very optimized already, but just cut out all the extraneous checks)Given that #3283 got a 1% speed-up, maybe this can get the same again, or maybe more?
@DonIsaac Would you be interested in investigating?
The text was updated successfully, but these errors were encountered: