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

perf(rome_rowan): SyntaxNodeText improvements #3217

Merged
merged 1 commit into from
Sep 14, 2022

Conversation

MichaReiser
Copy link
Contributor

This PR improves the performance of SyntaxNodeText by using the token_at_offset method rather than traversing over all tokens in the tree until it find the first token that has an overlapping range. Using token_at_offset has better performance because it only traverses into nodes that have an overlapping range.

Example: Getting the text for + e in ``a + b + c + d + e`

  • Old implementation: Traverses through the whole tree until it reaches the + token
  • New: Finds the + on the first level, then traverses into e

Doing this improvement I discovered that noShoutyConstants uses SyntaxNodeText over SyntaxTokenText. SyntaxTokenText has the better performance because it isn't necessary to find the first token with an overlapping range. So, I refactored the implementation to use SyntaxTokenText instead

Performance

group                                    main                                    text
-----                                    ----                                    ----
analyzer/css.js                          1.06  1238.1±109.59µs     9.4 MB/sec    1.00   1167.7±6.84µs     9.9 MB/sec
analyzer/index.js                        1.03      3.6±0.36ms     9.2 MB/sec     1.00      3.5±0.30ms     9.4 MB/sec
analyzer/lint.ts                         1.04      2.1±0.07ms    19.6 MB/sec     1.00      2.0±0.01ms    20.4 MB/sec
analyzer/parser.ts                       1.05      4.3±0.35ms    11.4 MB/sec     1.00      4.1±0.17ms    12.0 MB/sec
analyzer/router.ts                       1.00      2.8±0.14ms    21.9 MB/sec     1.02      2.9±0.02ms    21.5 MB/sec
analyzer/statement.ts                    1.00      3.8±0.17ms     9.3 MB/sec     1.01      3.8±0.12ms     9.3 MB/sec
analyzer/typescript.ts                   1.22      7.4±1.25ms     7.3 MB/sec     1.00      6.1±0.46ms     9.0 MB/sec

Test Plan

I added new doc tests and integration tests for the changes in rome_rowan and rome_text_size

This PR improves the performance of `SyntaxNodeText` by using the `token_at_offset` method rather than traversing over all tokens in the tree until it find the first token that has an overlapping range. Using `token_at_offset` has better performance because it only traverses into nodes that have an overlapping range.

Example: Getting the text for `+ e` in ``a + b + c + d + e`

* Old implementation: Traverses through the whole tree until it reaches the `+` token
* New: Finds the `+` on the first level, then traverses into `e`

Doing this improvement I discovered that `noShoutyConstants` uses `SyntaxNodeText` over `SyntaxTokenText`. `SyntaxTokenText` has the better performance because it isn't necessary to find the first token with an overlapping range. So, I refactored the implementation to use `SyntaxTokenText` instead

 ## Performance

 ```
 group                                    main                                    text
 -----                                    ----                                    ----
 analyzer/css.js                          1.06  1238.1±109.59µs     9.4 MB/sec    1.00   1167.7±6.84µs     9.9 MB/sec
 analyzer/index.js                        1.03      3.6±0.36ms     9.2 MB/sec     1.00      3.5±0.30ms     9.4 MB/sec
 analyzer/lint.ts                         1.04      2.1±0.07ms    19.6 MB/sec     1.00      2.0±0.01ms    20.4 MB/sec
 analyzer/parser.ts                       1.05      4.3±0.35ms    11.4 MB/sec     1.00      4.1±0.17ms    12.0 MB/sec
 analyzer/router.ts                       1.00      2.8±0.14ms    21.9 MB/sec     1.02      2.9±0.02ms    21.5 MB/sec
 analyzer/statement.ts                    1.00      3.8±0.17ms     9.3 MB/sec     1.01      3.8±0.12ms     9.3 MB/sec
 analyzer/typescript.ts                   1.22      7.4±1.25ms     7.3 MB/sec     1.00      6.1±0.46ms     9.0 MB/sec
```
@MichaReiser MichaReiser requested a review from a team September 14, 2022 08:12
@netlify
Copy link

netlify bot commented Sep 14, 2022

Deploy Preview for rometools canceled.

Name Link
🔨 Latest commit 9bc9111
🔍 Latest deploy log https://app.netlify.com/sites/rometools/deploys/63218d040440830008020858

@MichaReiser MichaReiser temporarily deployed to netlify-playground September 14, 2022 08:12 Inactive
@github-actions
Copy link

@github-actions
Copy link

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 45879 45879 0
Passed 44939 44939 0
Failed 940 940 0
Panics 0 0 0
Coverage 97.95% 97.95% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 39 39 0
Passed 36 36 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.31% 92.31% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5946 5946 0
Passed 1621 1621 0
Failed 4325 4325 0
Panics 0 0 0
Coverage 27.26% 27.26% 0.00%

ts/babel

Test result main count This PR count Difference
Total 588 588 0
Passed 519 519 0
Failed 69 69 0
Panics 0 0 0
Coverage 88.27% 88.27% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 16257 16257 0
Passed 12395 12395 0
Failed 3862 3862 0
Panics 0 0 0
Coverage 76.24% 76.24% 0.00%

@MichaReiser MichaReiser added the A-Linter Area: linter label Sep 14, 2022
@MichaReiser MichaReiser added this to the 0.10.0 milestone Sep 14, 2022
@MichaReiser MichaReiser merged commit 35d293f into main Sep 14, 2022
@MichaReiser MichaReiser deleted the perf/text-improvements branch September 14, 2022 09:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Linter Area: linter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载