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

refactor(rome_js_parser): APIs to create diagnostics #3429

Merged
merged 6 commits into from
Oct 19, 2022

Conversation

ematipico
Copy link
Contributor

@ematipico ematipico commented Oct 14, 2022

Summary

Closes #3424

  • now when creating a diagnostic, a range is mandatory; this makes sense in the parser, where diagnostics are always errors, hence we need a range where to locate the error;
  • .primary doesn't exist anymore
  • .secondary has been renamed in .detail, an API used to show more details around the error encountered
  • .footer_note has been renamed in .hint, a small message that should explain how an error can be fixed
  • fixed compiler issues inside the code coverage and bench suite

Test Plan

  • checked that the new diagnostics are conform to the changes I made;
  • run locally cargo bench_parser and made sure that works;
  • run locally cargo coverage and made sure that works;
group                   new-parser                              old-parser
-----                   ----------                              ----------
parser/checker.ts       1.14   106.1±17.21ms    24.5 MB/sec     1.00     92.9±3.64ms    28.0 MB/sec
parser/ios.d.ts         1.07     81.5±1.74ms    22.9 MB/sec     1.00     76.5±3.51ms    24.4 MB/sec
parser/jquery.min.js    1.06      8.7±0.65ms     9.5 MB/sec     1.00      8.2±0.18ms    10.1 MB/sec
parser/parser.ts        1.09      2.2±0.17ms    22.6 MB/sec     1.00  1967.4±90.94µs    24.8 MB/sec
parser/router.ts        1.09  1795.7±126.32µs    34.1 MB/sec    1.00  1641.5±55.83µs    37.3 MB/sec

@ematipico ematipico requested a review from a team October 14, 2022 15:42
@ematipico ematipico force-pushed the refactor/change-api-signature-parser branch from 86e41f6 to b0f79ef Compare October 14, 2022 15:53
@ematipico ematipico added A-Diagnostic Area: errors and diagnostics A-Parser Area: parser labels Oct 14, 2022
#[must_use]
pub fn err_builder(&self, message: &str) -> ParseDiagnostic {
ParseDiagnostic::new(self.file_id, message)
pub fn err_builder(&self, message: &str, span: impl AsSpan) -> ParseDiagnostic {
Copy link
Contributor

Choose a reason for hiding this comment

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

The message parameter could be typed to impl Into<String> (or even impl Display by changing the definition of ParseDiagnostic::new too) to allow the code using this function to pass in a String instance directly instead of having to allocate twice (for instance when doing .err_build(&format!()))

@ematipico ematipico force-pushed the refactor/parse-diagnostics branch 2 times, most recently from bbad581 to c21d763 Compare October 17, 2022 14:58
@MichaReiser
Copy link
Contributor

Do we have an understanding why it regresses performance in such a significant way? Particularly because the benchmarks only test programs without ANY diagnostic.

Base automatically changed from refactor/parse-diagnostics to refactor-diagnostics October 18, 2022 08:44
@ematipico ematipico force-pushed the refactor/change-api-signature-parser branch from b0f79ef to 39c7264 Compare October 18, 2022 08:59
@ematipico ematipico force-pushed the refactor/change-api-signature-parser branch from 39c7264 to 94dcedc Compare October 18, 2022 09:05
@ematipico
Copy link
Contributor Author

Do we have an understanding why it regresses performance in such a significant way? Particularly because the benchmarks only test programs without ANY diagnostic.

Personally I don't know 😞

@MichaReiser
Copy link
Contributor

Do we have an understanding why it regresses performance in such a significant way? Particularly because the benchmarks only test programs without ANY diagnostic.

Personally I don't know disappointed

Have you tried profiling a parser benchmark with the old diagnostic, then profile the same benchmark with the new diagnostics and compared the numbers? Are there any methods that now require significant more time? Have you tried running the benchmarks with dhat and compared the number of bytes written?

@ematipico
Copy link
Contributor Author

ematipico commented Oct 18, 2022

This branch

dhat: Total:     520,693,453 bytes in 1,919,700 blocks
dhat: At t-gmax: 111,962,958 bytes in 625,525 blocks
dhat: At t-end:  1,145 bytes in 3 blocks

main

dhat: Total:     545,632,486 bytes in 1,932,067 blocks
dhat: At t-gmax: 111,963,342 bytes in 625,525 blocks
dhat: At t-end:  1,145 bytes in 3 blocks

@@ -302,6 +302,8 @@ array_assignment_target_err.js:1:4 parse ━━━━━━━━━━━━━
2 │ [a, c, ...rest,] = test;
3 │ [a = , = "test"] = test;

i Remove a
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated to your change but a should probably be put in quotes :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that we can support markup, we can enrich these messages :)

@ematipico
Copy link
Contributor Author

I probably did something wrong when I run the benchmarks locally. I re-ran them again, in release mode:

group                                 new-diagnostics                        old-diagnostics
-----                                 ---------------                        ---------------
parser/checker.ts                     1.00     99.1±2.51ms    26.2 MB/sec    1.07   106.2±18.09ms    24.5 MB/sec
parser/compiler.js                    1.00     53.6±0.46ms    19.5 MB/sec    1.06     56.9±4.01ms    18.4 MB/sec
parser/d3.min.js                      1.02     33.9±0.67ms     7.7 MB/sec    1.00     33.1±0.47ms     7.9 MB/sec
parser/dojo.js                        1.01      3.0±0.51ms    23.0 MB/sec    1.00      2.9±0.05ms    23.3 MB/sec
parser/ios.d.ts                       1.00     83.8±2.30ms    22.3 MB/sec    1.03     86.0±1.97ms    21.7 MB/sec
parser/jquery.min.js                  1.00      8.4±0.15ms     9.8 MB/sec    1.06      9.0±0.25ms     9.2 MB/sec
parser/math.js                        1.00     69.0±0.48ms     9.4 MB/sec    1.01     69.4±2.20ms     9.3 MB/sec
parser/parser.ts                      1.00      2.2±0.02ms    22.2 MB/sec    1.08      2.4±0.29ms    20.6 MB/sec
parser/pixi.min.js                    1.00     44.2±0.56ms     9.9 MB/sec    1.18    52.0±12.77ms     8.4 MB/sec
parser/react-dom.production.min.js    1.00     11.8±0.12ms     9.8 MB/sec    1.13     13.3±0.97ms     8.6 MB/sec
parser/react.production.min.js        1.00   615.8±15.03µs    10.0 MB/sec    1.09   669.3±42.43µs     9.2 MB/sec
parser/router.ts                      1.00  1833.5±24.58µs    33.4 MB/sec    1.02  1869.4±112.64µs    32.8 MB/sec
parser/tex-chtml-full.js              1.00     92.5±2.58ms     9.8 MB/sec    1.04    96.1±13.63ms     9.5 MB/sec
parser/three.min.js                   1.00     48.9±0.87ms    12.0 MB/sec    1.13     55.4±7.29ms    10.6 MB/sec
parser/typescript.js                  1.00    401.0±9.51ms    23.7 MB/sec    1.06   423.4±71.51ms    22.4 MB/sec
parser/vue.global.prod.js             1.00     14.3±0.36ms     8.4 MB/sec    1.06     15.1±0.39ms     8.0 MB/sec

@ematipico
Copy link
Contributor Author

!bench_parser

@github-actions
Copy link

Parser Benchmark Results

group                                 main                                   pr
-----                                 ----                                   --
parser/checker.ts                     1.00    124.5±2.44ms    20.9 MB/sec    1.00    124.9±2.77ms    20.8 MB/sec
parser/compiler.js                    1.01     69.3±1.85ms    15.1 MB/sec    1.00     68.9±1.65ms    15.2 MB/sec
parser/d3.min.js                      1.00     41.0±0.47ms     6.4 MB/sec    1.01     41.5±0.60ms     6.3 MB/sec
parser/dojo.js                        1.00      3.6±0.01ms    19.1 MB/sec    1.01      3.6±0.01ms    18.9 MB/sec
parser/ios.d.ts                       1.00    108.8±1.61ms    17.2 MB/sec    1.01    109.6±1.14ms    17.0 MB/sec
parser/jquery.min.js                  1.00     11.2±0.05ms     7.4 MB/sec    1.01     11.3±0.04ms     7.3 MB/sec
parser/math.js                        1.00     83.9±1.45ms     7.7 MB/sec    1.02     86.0±1.57ms     7.5 MB/sec
parser/parser.ts                      1.00      2.5±0.01ms    19.3 MB/sec    1.01      2.6±0.00ms    19.0 MB/sec
parser/pixi.min.js                    1.01     52.8±1.30ms     8.3 MB/sec    1.00     52.4±1.14ms     8.4 MB/sec
parser/react-dom.production.min.js    1.00     15.1±0.06ms     7.6 MB/sec    1.01     15.2±0.09ms     7.6 MB/sec
parser/react.production.min.js        1.00    776.3±1.37µs     7.9 MB/sec    1.01    786.2±1.66µs     7.8 MB/sec
parser/router.ts                      1.00      2.1±0.00ms    29.0 MB/sec    1.01      2.1±0.01ms    28.6 MB/sec
parser/tex-chtml-full.js              1.00    118.2±1.27ms     7.7 MB/sec    1.01    119.5±1.66ms     7.6 MB/sec
parser/three.min.js                   1.00     58.4±1.30ms    10.0 MB/sec    1.00     58.2±1.21ms    10.1 MB/sec
parser/typescript.js                  1.00    511.5±5.36ms    18.6 MB/sec    1.00    509.1±3.79ms    18.7 MB/sec
parser/vue.global.prod.js             1.00     18.4±0.08ms     6.6 MB/sec    1.01     18.6±0.08ms     6.5 MB/sec

@ematipico ematipico merged commit dc875a3 into refactor-diagnostics Oct 19, 2022
@ematipico ematipico deleted the refactor/change-api-signature-parser branch October 19, 2022 08:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Diagnostic Area: errors and diagnostics A-Parser Area: parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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