Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

perf(rowan): Speedup next_token and prev_token implementations #2612

Merged
merged 1 commit into from
May 25, 2022

Conversation

MichaReiser
Copy link
Contributor

Hand write the traversal of next_token and prev_token to speedup the traversal.

The new comment formatting will make heavy use of these two methods which is why it's important that they are fast.

❯ critcmp main fused
group                                    PR                                  main
-----                                    -----                                  ----
formatter/checker.ts                     1.00    239.2±1.22ms    10.9 MB/sec    1.01    240.8±3.49ms    10.8 MB/sec
formatter/compiler.js                    1.00    139.6±3.00ms     7.5 MB/sec    1.04    145.4±1.99ms     7.2 MB/sec
formatter/d3.min.js                      1.00    104.7±1.04ms     2.5 MB/sec    1.04    108.9±2.69ms     2.4 MB/sec
formatter/dojo.js                        1.00      7.8±0.11ms     8.8 MB/sec    1.02      7.9±0.01ms     8.6 MB/sec
formatter/ios.d.ts                       1.00    189.0±3.27ms     9.9 MB/sec    1.01    190.0±1.41ms     9.8 MB/sec
formatter/jquery.min.js                  1.00     29.5±0.43ms     2.8 MB/sec    1.00     29.4±0.23ms     2.8 MB/sec
formatter/math.js                        1.00    225.6±0.95ms     2.9 MB/sec    1.04    235.4±4.01ms     2.8 MB/sec
formatter/parser.ts                      1.02      5.6±0.01ms     8.7 MB/sec    1.00      5.5±0.09ms     8.8 MB/sec
formatter/pixi.min.js                    1.00    120.9±1.96ms     3.6 MB/sec    1.12   135.3±19.62ms     3.2 MB/sec
formatter/react-dom.production.min.js    1.00     35.4±0.54ms     3.2 MB/sec    1.05     37.3±0.39ms     3.1 MB/sec
formatter/react.production.min.js        1.00   1815.8±3.00µs     3.4 MB/sec    1.01  1833.6±29.27µs     3.4 MB/sec
formatter/router.ts                      1.01      4.1±0.01ms    14.8 MB/sec    1.00      4.1±0.08ms    15.0 MB/sec
formatter/tex-chtml-full.js              1.00    285.8±1.28ms     3.2 MB/sec    1.04    297.2±1.77ms     3.1 MB/sec
formatter/three.min.js                   1.00    142.0±1.02ms     4.1 MB/sec    1.05    148.7±4.29ms     3.9 MB/sec
formatter/typescript.js                  1.00   957.2±94.68ms     9.9 MB/sec    1.01   967.2±20.72ms     9.8 MB/sec
formatter/vue.global.prod.js             1.00     47.7±0.19ms     2.5 MB/sec    1.02     48.7±0.39ms     2.5 MB/sec

@MichaReiser MichaReiser requested a review from leops May 25, 2022 08:34
@MichaReiser MichaReiser temporarily deployed to aws May 25, 2022 08:34 Inactive
Hand write the traversal of `next_token` and `prev_token` to speedup the traversal.

The new comment formatting will make heavy use of these two methods which is why it's important that they are fast.

```
❯ critcmp main fused
group                                    PR                                  main
-----                                    -----                                  ----
formatter/checker.ts                     1.00    239.2±1.22ms    10.9 MB/sec    1.01    240.8±3.49ms    10.8 MB/sec
formatter/compiler.js                    1.00    139.6±3.00ms     7.5 MB/sec    1.04    145.4±1.99ms     7.2 MB/sec
formatter/d3.min.js                      1.00    104.7±1.04ms     2.5 MB/sec    1.04    108.9±2.69ms     2.4 MB/sec
formatter/dojo.js                        1.00      7.8±0.11ms     8.8 MB/sec    1.02      7.9±0.01ms     8.6 MB/sec
formatter/ios.d.ts                       1.00    189.0±3.27ms     9.9 MB/sec    1.01    190.0±1.41ms     9.8 MB/sec
formatter/jquery.min.js                  1.00     29.5±0.43ms     2.8 MB/sec    1.00     29.4±0.23ms     2.8 MB/sec
formatter/math.js                        1.00    225.6±0.95ms     2.9 MB/sec    1.04    235.4±4.01ms     2.8 MB/sec
formatter/parser.ts                      1.02      5.6±0.01ms     8.7 MB/sec    1.00      5.5±0.09ms     8.8 MB/sec
formatter/pixi.min.js                    1.00    120.9±1.96ms     3.6 MB/sec    1.12   135.3±19.62ms     3.2 MB/sec
formatter/react-dom.production.min.js    1.00     35.4±0.54ms     3.2 MB/sec    1.05     37.3±0.39ms     3.1 MB/sec
formatter/react.production.min.js        1.00   1815.8±3.00µs     3.4 MB/sec    1.01  1833.6±29.27µs     3.4 MB/sec
formatter/router.ts                      1.01      4.1±0.01ms    14.8 MB/sec    1.00      4.1±0.08ms    15.0 MB/sec
formatter/tex-chtml-full.js              1.00    285.8±1.28ms     3.2 MB/sec    1.04    297.2±1.77ms     3.1 MB/sec
formatter/three.min.js                   1.00    142.0±1.02ms     4.1 MB/sec    1.05    148.7±4.29ms     3.9 MB/sec
formatter/typescript.js                  1.00   957.2±94.68ms     9.9 MB/sec    1.01   967.2±20.72ms     9.8 MB/sec
formatter/vue.global.prod.js             1.00     47.7±0.19ms     2.5 MB/sec    1.02     48.7±0.39ms     2.5 MB/sec
```
@MichaReiser MichaReiser temporarily deployed to aws May 25, 2022 08:35 Inactive
@github-actions
Copy link

github-actions bot commented May 25, 2022

@MichaReiser
Copy link
Contributor Author

!bench_formatter

@cloudflare-workers-and-pages
Copy link

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: ca5c492
Status: ✅  Deploy successful!
Preview URL: https://91adc873.tools-8rn.pages.dev

View logs

@github-actions
Copy link

Formatter Benchmark Results

group                                    main                                   pr
-----                                    ----                                   --
formatter/checker.ts                     1.05    437.6±0.95ms     5.9 MB/sec    1.00    417.6±0.88ms     6.2 MB/sec
formatter/compiler.js                    1.06    266.3±0.78ms     3.9 MB/sec    1.00    251.8±0.77ms     4.2 MB/sec
formatter/d3.min.js                      1.06    206.6±0.78ms  1299.3 KB/sec    1.00    195.3±0.76ms  1374.3 KB/sec
formatter/dojo.js                        1.06     15.0±0.03ms     4.6 MB/sec    1.00     14.2±0.01ms     4.8 MB/sec
formatter/ios.d.ts                       1.07    338.5±0.62ms     5.5 MB/sec    1.00    315.2±1.02ms     5.9 MB/sec
formatter/jquery.min.js                  1.05     56.8±0.25ms  1489.9 KB/sec    1.00     54.2±0.50ms  1561.7 KB/sec
formatter/math.js                        1.04    412.6±0.85ms  1607.1 KB/sec    1.00    395.4±0.87ms  1677.1 KB/sec
formatter/parser.ts                      1.06     10.5±0.01ms     4.6 MB/sec    1.00      9.9±0.03ms     4.9 MB/sec
formatter/pixi.min.js                    1.05    234.3±0.52ms  1917.8 KB/sec    1.00    222.4±1.11ms  2021.0 KB/sec
formatter/react-dom.production.min.js    1.06     71.5±0.27ms  1649.2 KB/sec    1.00     67.7±0.42ms  1740.8 KB/sec
formatter/react.production.min.js        1.06      3.5±0.01ms  1790.2 KB/sec    1.00      3.3±0.01ms  1892.9 KB/sec
formatter/router.ts                      1.05      7.8±0.01ms     7.9 MB/sec    1.00      7.4±0.02ms     8.3 MB/sec
formatter/tex-chtml-full.js              1.04    521.8±1.39ms  1788.5 KB/sec    1.00    500.2±0.76ms  1865.4 KB/sec
formatter/three.min.js                   1.06    269.1±0.73ms     2.2 MB/sec    1.00    254.5±0.63ms     2.3 MB/sec
formatter/typescript.js                  1.05   1658.0±3.42ms     5.7 MB/sec    1.00   1581.4±2.45ms     6.0 MB/sec
formatter/vue.global.prod.js             1.06     93.5±0.48ms  1320.0 KB/sec    1.00     88.5±0.58ms  1393.6 KB/sec

@MichaReiser MichaReiser merged commit 0e51385 into main May 25, 2022
@MichaReiser MichaReiser deleted the perf/next-prev-token branch May 25, 2022 09:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants