Skip to content

Commit

Permalink
perf(es/parser): Add a check before numeric operations (#9105)
Browse files Browse the repository at this point in the history
**Description:**

`c.is_ascii_uppercase()` was expensive than expected.
  • Loading branch information
kdy1 authored Jun 25, 2024
1 parent 56f0367 commit c0602c8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ impl<'a> Lexer<'a> {
loop {
if let Some(c) = l.input.cur_as_ascii() {
// Performance optimization
if c.is_ascii_uppercase() || c.is_ascii_digit() {
if can_be_keyword && (c.is_ascii_uppercase() || c.is_ascii_digit()) {
can_be_keyword = false;
}

Expand Down

1 comment on commit c0602c8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: c0602c8 Previous: 2a490ad Ratio
es/full/bugs-1 274082 ns/iter (± 2620) 274143 ns/iter (± 2068) 1.00
es/full/minify/libraries/antd 1859303119 ns/iter (± 67284245) 1770843326 ns/iter (± 98748223) 1.05
es/full/minify/libraries/d3 358671942 ns/iter (± 4784875) 345276531 ns/iter (± 5055829) 1.04
es/full/minify/libraries/echarts 1668433104 ns/iter (± 31982412) 1480442528 ns/iter (± 45192316) 1.13
es/full/minify/libraries/jquery 105896653 ns/iter (± 687705) 102464592 ns/iter (± 195744) 1.03
es/full/minify/libraries/lodash 115979077 ns/iter (± 1353914) 113855468 ns/iter (± 452200) 1.02
es/full/minify/libraries/moment 60268708 ns/iter (± 307677) 59637696 ns/iter (± 174198) 1.01
es/full/minify/libraries/react 18319651 ns/iter (± 91693) 18229911 ns/iter (± 395317) 1.00
es/full/minify/libraries/terser 275087977 ns/iter (± 5860760) 279365061 ns/iter (± 4546804) 0.98
es/full/minify/libraries/three 478679319 ns/iter (± 5745718) 491016455 ns/iter (± 31203314) 0.97
es/full/minify/libraries/typescript 3199796015 ns/iter (± 30705977) 3393840499 ns/iter (± 98976473) 0.94
es/full/minify/libraries/victory 856289342 ns/iter (± 55752964) 800980942 ns/iter (± 58188335) 1.07
es/full/minify/libraries/vue 145754512 ns/iter (± 777692) 151599100 ns/iter (± 2951580) 0.96
es/full/codegen/es3 57969 ns/iter (± 538) 61478 ns/iter (± 634) 0.94
es/full/codegen/es5 57952 ns/iter (± 182) 61521 ns/iter (± 390) 0.94
es/full/codegen/es2015 57772 ns/iter (± 262) 61521 ns/iter (± 446) 0.94
es/full/codegen/es2016 57783 ns/iter (± 163) 61579 ns/iter (± 814) 0.94
es/full/codegen/es2017 57878 ns/iter (± 229) 61087 ns/iter (± 494) 0.95
es/full/codegen/es2018 57853 ns/iter (± 223) 61499 ns/iter (± 867) 0.94
es/full/codegen/es2019 57949 ns/iter (± 281) 61579 ns/iter (± 740) 0.94
es/full/codegen/es2020 58230 ns/iter (± 213) 61228 ns/iter (± 462) 0.95
es/full/all/es3 158665887 ns/iter (± 908043) 156521218 ns/iter (± 482029) 1.01
es/full/all/es5 153667597 ns/iter (± 900782) 152283676 ns/iter (± 1031556) 1.01
es/full/all/es2015 112595137 ns/iter (± 908638) 112243916 ns/iter (± 987034) 1.00
es/full/all/es2016 111992458 ns/iter (± 790961) 110269929 ns/iter (± 461887) 1.02
es/full/all/es2017 111234745 ns/iter (± 558585) 109826433 ns/iter (± 716871) 1.01
es/full/all/es2018 108857249 ns/iter (± 597028) 107513673 ns/iter (± 440937) 1.01
es/full/all/es2019 107674030 ns/iter (± 692980) 107123354 ns/iter (± 285768) 1.01
es/full/all/es2020 104316334 ns/iter (± 506174) 103882806 ns/iter (± 957883) 1.00
es/full/parser 424310 ns/iter (± 2281) 424065 ns/iter (± 2162) 1.00
es/full/base/fixer 15407 ns/iter (± 85) 15969 ns/iter (± 233) 0.96
es/full/base/resolver_and_hygiene 80040 ns/iter (± 166) 80471 ns/iter (± 148) 0.99
serialization of serde 271 ns/iter (± 8) 253 ns/iter (± 10) 1.07
css/minify/libraries/bootstrap 21874967 ns/iter (± 36017) 22283284 ns/iter (± 16641) 0.98
css/visitor/compare/clone 1376986 ns/iter (± 10984) 1384572 ns/iter (± 15300) 0.99
css/visitor/compare/visit_mut_span 1506696 ns/iter (± 11732) 1517963 ns/iter (± 18635) 0.99
css/visitor/compare/visit_mut_span_panic 1514681 ns/iter (± 46121) 1507455 ns/iter (± 1820) 1.00
css/visitor/compare/fold_span 2007886 ns/iter (± 8771) 2028365 ns/iter (± 9176) 0.99
css/visitor/compare/fold_span_panic 2145991 ns/iter (± 7071) 2148134 ns/iter (± 4570) 1.00
css/lexer/bootstrap_5_1_3 3461906 ns/iter (± 15483) 3450549 ns/iter (± 4128) 1.00
css/lexer/foundation_6_7_4 2807718 ns/iter (± 2962) 2808216 ns/iter (± 5629) 1.00
css/lexer/tailwind_3_1_1 539238 ns/iter (± 4440) 538823 ns/iter (± 520) 1.00
css/parser/bootstrap_5_1_3 16612549 ns/iter (± 45314) 15939884 ns/iter (± 37770) 1.04
css/parser/foundation_6_7_4 13226729 ns/iter (± 149615) 12783550 ns/iter (± 53641) 1.03
css/parser/tailwind_3_1_1 2602224 ns/iter (± 8545) 2527639 ns/iter (± 26830) 1.03
es/codegen/colors 729675 ns/iter (± 401082) 748246 ns/iter (± 393907) 0.98
es/codegen/large 2862851 ns/iter (± 1541915) 2989696 ns/iter (± 1595304) 0.96
es/codegen/with-parser/colors 42447 ns/iter (± 804) 38946 ns/iter (± 394) 1.09
es/codegen/with-parser/large 476802 ns/iter (± 47404) 443490 ns/iter (± 4676) 1.08
es/minify/libraries/antd 1537764475 ns/iter (± 24465264) 1412911649 ns/iter (± 27013873) 1.09
es/minify/libraries/d3 303369685 ns/iter (± 12173969) 286866934 ns/iter (± 9681735) 1.06
es/minify/libraries/echarts 1259308623 ns/iter (± 14551672) 1248799217 ns/iter (± 18601774) 1.01
es/minify/libraries/jquery 82712964 ns/iter (± 316487) 82237180 ns/iter (± 394437) 1.01
es/minify/libraries/lodash 105300016 ns/iter (± 825865) 103910801 ns/iter (± 150133) 1.01
es/minify/libraries/moment 48578169 ns/iter (± 333970) 47913824 ns/iter (± 301923) 1.01
es/minify/libraries/react 16327551 ns/iter (± 45349) 16124811 ns/iter (± 105334) 1.01
es/minify/libraries/terser 233933941 ns/iter (± 4101839) 219033065 ns/iter (± 3506246) 1.07
es/minify/libraries/three 410163163 ns/iter (± 22287731) 364029084 ns/iter (± 3975554) 1.13
es/minify/libraries/typescript 2795001845 ns/iter (± 38682821) 2714029136 ns/iter (± 20550635) 1.03
es/minify/libraries/victory 613598069 ns/iter (± 7556082) 576507717 ns/iter (± 15582819) 1.06
es/minify/libraries/vue 124509692 ns/iter (± 1449331) 120623844 ns/iter (± 716282) 1.03
es/visitor/compare/clone 1743697 ns/iter (± 8600) 1727380 ns/iter (± 9630) 1.01
es/visitor/compare/visit_mut_span 2089390 ns/iter (± 8023) 2093150 ns/iter (± 17666) 1.00
es/visitor/compare/visit_mut_span_panic 2091567 ns/iter (± 30623) 2091264 ns/iter (± 41422) 1.00
es/visitor/compare/fold_span 2807371 ns/iter (± 13953) 2895607 ns/iter (± 36509) 0.97
es/visitor/compare/fold_span_panic 2864858 ns/iter (± 18068) 2878461 ns/iter (± 52139) 1.00
es/lexer/colors 8692 ns/iter (± 38) 8600 ns/iter (± 166) 1.01
es/lexer/angular 4186817 ns/iter (± 17841) 4242660 ns/iter (± 45611) 0.99
es/lexer/backbone 642627 ns/iter (± 5522) 634806 ns/iter (± 6444) 1.01
es/lexer/jquery 3535465 ns/iter (± 6197) 3652310 ns/iter (± 12108) 0.97
es/lexer/jquery mobile 5276727 ns/iter (± 38127) 5065001 ns/iter (± 87887) 1.04
es/lexer/mootools 2824583 ns/iter (± 5035) 2732413 ns/iter (± 22625) 1.03
es/lexer/underscore 525150 ns/iter (± 1160) 530999 ns/iter (± 2115) 0.99
es/lexer/three 15983580 ns/iter (± 27003) 15995206 ns/iter (± 24073) 1.00
es/lexer/yui 2758730 ns/iter (± 4118) 2666828 ns/iter (± 1772) 1.03
es/lexer/cal-com 12885133 ns/iter (± 23029) 12606957 ns/iter (± 24993) 1.02
es/lexer/typescript 93457164 ns/iter (± 469433) 90037076 ns/iter (± 323064) 1.04
es/parser/colors 22445 ns/iter (± 154) 22374 ns/iter (± 185) 1.00
es/parser/angular 11833877 ns/iter (± 160114) 11774123 ns/iter (± 130688) 1.01
es/parser/backbone 1810362 ns/iter (± 7599) 1808807 ns/iter (± 10622) 1.00
es/parser/jquery 10065783 ns/iter (± 81467) 9977179 ns/iter (± 62770) 1.01
es/parser/jquery mobile 15687128 ns/iter (± 392488) 15075052 ns/iter (± 93826) 1.04
es/parser/mootools 7792080 ns/iter (± 98607) 7778326 ns/iter (± 58810) 1.00
es/parser/underscore 1584690 ns/iter (± 7051) 1579882 ns/iter (± 9180) 1.00
es/parser/three 45450181 ns/iter (± 554532) 43855292 ns/iter (± 325533) 1.04
es/parser/yui 7313280 ns/iter (± 73279) 7284631 ns/iter (± 33329) 1.00
es/parser/cal-com 41315682 ns/iter (± 661368) 39400168 ns/iter (± 459533) 1.05
es/parser/typescript 275279658 ns/iter (± 1690750) 269268106 ns/iter (± 2222613) 1.02
es/preset-env/usage/builtin_type 135884 ns/iter (± 33385) 138620 ns/iter (± 34139) 0.98
es/preset-env/usage/property 17381 ns/iter (± 97) 17267 ns/iter (± 155) 1.01
es/resolver/typescript 103737124 ns/iter (± 2050784) 101183183 ns/iter (± 3029684) 1.03
es/fixer/typescript 79822490 ns/iter (± 2974280) 80844256 ns/iter (± 5512422) 0.99
es/hygiene/typescript 178967473 ns/iter (± 5137377) 177790159 ns/iter (± 4541344) 1.01
es/resolver_with_hygiene/typescript 304325025 ns/iter (± 6409342) 305256076 ns/iter (± 3701160) 1.00
es/visitor/base-perf/module_clone 56777 ns/iter (± 680) 57182 ns/iter (± 560) 0.99
es/visitor/base-perf/fold_empty 60068 ns/iter (± 382) 60131 ns/iter (± 788) 1.00
es/visitor/base-perf/fold_noop_impl_all 60453 ns/iter (± 547) 60532 ns/iter (± 553) 1.00
es/visitor/base-perf/fold_noop_impl_vec 59938 ns/iter (± 1080) 60625 ns/iter (± 397) 0.99
es/visitor/base-perf/boxing_boxed_clone 60 ns/iter (± 0) 60 ns/iter (± 0) 1
es/visitor/base-perf/boxing_unboxed_clone 47 ns/iter (± 0) 47 ns/iter (± 0) 1
es/visitor/base-perf/boxing_boxed 105 ns/iter (± 0) 106 ns/iter (± 0) 0.99
es/visitor/base-perf/boxing_unboxed 80 ns/iter (± 0) 81 ns/iter (± 1) 0.99
es/visitor/base-perf/visit_contains_this 2581 ns/iter (± 12) 2587 ns/iter (± 15) 1.00
es/base/parallel/resolver/typescript 2443015871 ns/iter (± 145346324) 2473882153 ns/iter (± 94735689) 0.99
es/base/parallel/hygiene/typescript 3207735004 ns/iter (± 49389563) 3208706867 ns/iter (± 45116114) 1.00
babelify-only 498769 ns/iter (± 9262) 492281 ns/iter (± 8722) 1.01
parse_and_babelify_angular 45972099 ns/iter (± 851028) 43520865 ns/iter (± 1542478) 1.06
parse_and_babelify_backbone 4482983 ns/iter (± 226934) 4376115 ns/iter (± 145997) 1.02
parse_and_babelify_jquery 31869437 ns/iter (± 1303178) 28847516 ns/iter (± 256888) 1.10
parse_and_babelify_jquery_mobile 54424159 ns/iter (± 3278430) 49677521 ns/iter (± 1055457) 1.10
parse_and_babelify_mootools 28187123 ns/iter (± 1093401) 26246212 ns/iter (± 409724) 1.07
parse_and_babelify_underscore 3679736 ns/iter (± 28566) 3675332 ns/iter (± 26785) 1.00
parse_and_babelify_yui 28499648 ns/iter (± 3064695) 24229726 ns/iter (± 301427) 1.18
html/minify/document/css_spec 46709914 ns/iter (± 1740048) 45652467 ns/iter (± 266621) 1.02
html/minify/document/github 18315264 ns/iter (± 75821) 18304852 ns/iter (± 243333) 1.00
html/minify/document/stackoverflow 16928361 ns/iter (± 476425) 16685324 ns/iter (± 245385) 1.01
html/minify/document_fragment/css_spec 44874572 ns/iter (± 285283) 44485143 ns/iter (± 102876) 1.01
html/minify/document_fragment/github 17977561 ns/iter (± 66595) 17945363 ns/iter (± 18221) 1.00
html/minify/document_fragment/stackoverflow 16818836 ns/iter (± 297249) 16447831 ns/iter (± 41622) 1.02
html/document/visitor/compare/clone 165248 ns/iter (± 2338) 166422 ns/iter (± 1675) 0.99
html/document/visitor/compare/visit_mut_span 182919 ns/iter (± 1578) 183013 ns/iter (± 1504) 1.00
html/document/visitor/compare/visit_mut_span_panic 188297 ns/iter (± 9164) 186995 ns/iter (± 4212) 1.01
html/document/visitor/compare/fold_span 227802 ns/iter (± 1153) 231411 ns/iter (± 966) 0.98
html/document/visitor/compare/fold_span_panic 281111 ns/iter (± 2026) 279976 ns/iter (± 1170) 1.00
html/document_fragment/visitor/compare/clone 164413 ns/iter (± 1755) 166818 ns/iter (± 1502) 0.99
html/document_fragment/visitor/compare/visit_mut_span 181344 ns/iter (± 1335) 185199 ns/iter (± 1249) 0.98
html/document_fragment/visitor/compare/visit_mut_span_panic 186895 ns/iter (± 1451) 186838 ns/iter (± 1082) 1.00
html/document_fragment/visitor/compare/fold_span 229908 ns/iter (± 725) 231924 ns/iter (± 1211) 0.99
html/document_fragment/visitor/compare/fold_span_panic 279226 ns/iter (± 1816) 277517 ns/iter (± 1119) 1.01
html/lexer/css_2021_spec 12985388 ns/iter (± 22242) 13031778 ns/iter (± 136567) 1.00
html/lexer/github_com_17_05_2022 4962804 ns/iter (± 45347) 5007351 ns/iter (± 13681) 0.99
html/lexer/stackoverflow_com_17_05_2022 4732570 ns/iter (± 9786) 4749850 ns/iter (± 7272) 1.00
html/parser/parser_document/css_2021_spec 25627141 ns/iter (± 172440) 26707697 ns/iter (± 65161) 0.96
html/parser/parser_document/github_com_17_05_2022 8583699 ns/iter (± 33009) 8874153 ns/iter (± 26085) 0.97
html/parser/parser_document/stackoverflow_com_17_05_2022 7524445 ns/iter (± 15706) 7828950 ns/iter (± 12698) 0.96
html/parser/parser_document_fragment/css_2021_spec 25501158 ns/iter (± 113460) 25363324 ns/iter (± 80014) 1.01
html/parser/parser_document_fragment/github_com_17_05_2022 8552630 ns/iter (± 15343) 8567242 ns/iter (± 9137) 1.00
html/parser/parser_document_fragment/stackoverflow_com_17_05_2022 7539844 ns/iter (± 140662) 7405995 ns/iter (± 4545) 1.02

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.