Fast path for parsing decimal literals #3288
Labels
A-parser
Area - Parser
C-performance
Category - Solution not expected to change functional behavior, only performance
#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: