-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Improve ux for rust users #909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
9ce0162 to
b629cda
Compare
common/src/comments.rs
Outdated
| fn take_leading(&self, pos: BytePos) -> Option<Vec<Comment>> { | ||
| (**self).take_leading(pos) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to have get_leading(&self, pos: BytePos) -> Option<&[&Comment]> and respective method for trailing ones?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect it to require another complex generic traits.
But api like
fn with_leading<F, Ret>(&self, op: F) -> Ret where F: FnOnce(&[Comment]) -> Ret;is possible, regardless of threadedness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, that would work for my use case 👍
|
cc @ry @bartlomieju as I'm almost done. I'll add more span tests via other prs. |
This will help preventing stack overflow
| /// [&Comments] to the parser. Thirdly, `(&self)` allows multi-threaded | ||
| /// use-cases such as swc itself. | ||
| /// | ||
| /// We use [Option] instead of no-op Comments implementation to avoid allocation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK Empty vec doesn't allocate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct, but to avoid allocation in parser, you need to determine if comment parser is enabled.
It can be done by passing comment map whilest passing a flag to parser, but Option<&dyn Comments> can be used as a comment map combined with a flag.
Comments refinement
Comments is now trait and swc_common only contains single-threaded
Commentsimpl.This allow dropping dependency on dashmap.
Multi-threaded implementation of
Commentswill live in theswccrate.Span testing
It's bit messy, but span is rendered with code.
Closes #583.
No duplicated comments
Lexer now insert comments only if start of it is after last comment. This variable is shared, so even when the parser decides to backtrack, comments are not duplicated.
Closes #856.
Span,
GLOBALSissueThis is about making
swc_common::GLOBALSnot required whiling parsing.Benachmark:
Parser benchmark with compressed span
test lexer::tests::lex_colors_js ... bench: 29,862 ns/iter (+/- 677) = 38 MB/s
test lexer::tests::lex_colors_ts ... bench: 30,328 ns/iter (+/- 4,249) = 38 MB/s
test lexer::tests::lex_dec_lit ... bench: 39,349 ns/iter (+/- 3,514) = 13 MB/s
test lexer::tests::lex_escaped_char ... bench: 9,008 ns/iter (+/- 2,104) = 25 MB/s
test lexer::tests::lex_ident ... bench: 34,146 ns/iter (+/- 905) = 16 MB/s
test lexer::tests::lex_large_number ... bench: 13,607 ns/iter (+/- 2,067) = 16 MB/s
test lexer::tests::lex_legact_octal_lit ... bench: 65,269 ns/iter (+/- 6,505) = 9 MB/s
test lexer::tests::lex_long_ident ... bench: 6,393 ns/iter (+/- 427) = 74 MB/s
test lexer::tests::lex_regex ... bench: 11,146 ns/iter (+/- 837) = 13 MB/s
test lexer::tests::lex_semicolons ... bench: 164,109 ns/iter (+/- 11,798) = 11 MB/s
test parser::expr::tests::bench_member_expr_es ... bench: 4,944 ns/iter (+/- 415) = 2 MB/s
test parser::expr::tests::bench_member_expr_ts ... bench: 5,199 ns/iter (+/- 545) = 2 MB/s
test parser::expr::tests::bench_new_expr_es ... bench: 2,665 ns/iter (+/- 583) = 3 MB/s
test parser::expr::tests::bench_new_expr_ts ... bench: 2,876 ns/iter (+/- 391) = 3 MB/s
test result: ok. 0 passed; 0 failed; 137 ignored; 14 measured; 0 filtered out
running 8 tests
test angular ... bench: 12,073,907 ns/iter (+/- 223,565) = 59 MB/s
test backbone ... bench: 1,516,604 ns/iter (+/- 73,519) = 39 MB/s
test colors ... bench: 25,818 ns/iter (+/- 2,599) = 44 MB/s
test jquery ... bench: 8,338,700 ns/iter (+/- 186,822) = 32 MB/s
test jquery_mobile ... bench: 13,596,096 ns/iter (+/- 311,483) = 33 MB/s
test mootools ... bench: 6,370,238 ns/iter (+/- 204,655) = 25 MB/s
test underscore ... bench: 1,248,574 ns/iter (+/- 22,867) = 34 MB/s
test yui ... bench: 6,964,947 ns/iter (+/- 111,208) = 48 MB/s
test result: ok. 0 passed; 0 failed; 0 ignored; 8 measured; 0 filtered out
running 17 tests
test angular ... bench: 31,571,375 ns/iter (+/- 929,317) = 22 MB/s
test angular_ts ... bench: 33,139,153 ns/iter (+/- 1,329,377) = 21 MB/s
test backbone ... bench: 4,143,316 ns/iter (+/- 121,542) = 14 MB/s
test backbone_ts ... bench: 4,321,886 ns/iter (+/- 191,845) = 13 MB/s
test colors ... bench: 56,804 ns/iter (+/- 63,156) = 20 MB/s
test colors_ts ... bench: 58,379 ns/iter (+/- 36,899) = 19 MB/s
test jquery ... bench: 24,677,749 ns/iter (+/- 931,515) = 10 MB/s
test jquery_mobile ... bench: 40,658,794 ns/iter (+/- 1,473,480) = 11 MB/s
test jquery_mobile_ts ... bench: 41,106,544 ns/iter (+/- 1,307,308) = 11 MB/s
test jquery_ts ... bench: 25,117,499 ns/iter (+/- 508,530) = 10 MB/s
test large ... bench: 733,485 ns/iter (+/- 30,160) = 6 MB/s
test mootools ... bench: 19,319,509 ns/iter (+/- 473,669) = 8 MB/s
test mootools_ts ... bench: 19,977,002 ns/iter (+/- 627,177) = 8 MB/s
test underscore ... bench: 3,497,250 ns/iter (+/- 110,568) = 12 MB/s
test underscore_ts ... bench: 3,704,073 ns/iter (+/- 126,591) = 11 MB/s
test yui ... bench: 18,210,932 ns/iter (+/- 667,750) = 18 MB/s
test yui_ts ... bench: 19,198,935 ns/iter (+/- 403,819) = 17 MB/s
test result: ok. 0 passed; 0 failed; 0 ignored; 17 measured; 0 filtered out
Parser benchmark without span compression
test lexer::tests::lex_colors_js ... bench: 29,885 ns/iter (+/- 2,840) = 38 MB/s
test lexer::tests::lex_colors_ts ... bench: 30,181 ns/iter (+/- 3,857) = 38 MB/s
test lexer::tests::lex_dec_lit ... bench: 38,751 ns/iter (+/- 1,476) = 13 MB/s
test lexer::tests::lex_escaped_char ... bench: 9,036 ns/iter (+/- 1,625) = 25 MB/s
test lexer::tests::lex_ident ... bench: 34,185 ns/iter (+/- 4,779) = 16 MB/s
test lexer::tests::lex_large_number ... bench: 13,465 ns/iter (+/- 991) = 16 MB/s
test lexer::tests::lex_legact_octal_lit ... bench: 64,013 ns/iter (+/- 10,854) = 9 MB/s
test lexer::tests::lex_long_ident ... bench: 6,381 ns/iter (+/- 1,075) = 74 MB/s
test lexer::tests::lex_regex ... bench: 11,151 ns/iter (+/- 2,097) = 13 MB/s
test lexer::tests::lex_semicolons ... bench: 162,000 ns/iter (+/- 14,307) = 11 MB/s
test parser::expr::tests::bench_member_expr_es ... bench: 4,942 ns/iter (+/- 223) = 2 MB/s
test parser::expr::tests::bench_member_expr_ts ... bench: 5,115 ns/iter (+/- 663) = 2 MB/s
test parser::expr::tests::bench_new_expr_es ... bench: 2,562 ns/iter (+/- 263) = 3 MB/s
test parser::expr::tests::bench_new_expr_ts ... bench: 2,822 ns/iter (+/- 378) = 3 MB/s
test result: ok. 0 passed; 0 failed; 137 ignored; 14 measured; 0 filtered out
running 8 tests
test angular ... bench: 11,844,198 ns/iter (+/- 277,584) = 60 MB/s
test backbone ... bench: 1,495,697 ns/iter (+/- 97,404) = 40 MB/s
test colors ... bench: 25,441 ns/iter (+/- 2,405) = 45 MB/s
test jquery ... bench: 8,276,801 ns/iter (+/- 197,501) = 32 MB/s
test jquery_mobile ... bench: 13,395,942 ns/iter (+/- 320,989) = 33 MB/s
test mootools ... bench: 6,323,569 ns/iter (+/- 184,925) = 25 MB/s
test underscore ... bench: 1,236,126 ns/iter (+/- 83,913) = 35 MB/s
test yui ... bench: 6,843,345 ns/iter (+/- 134,186) = 49 MB/s
test result: ok. 0 passed; 0 failed; 0 ignored; 8 measured; 0 filtered out
running 17 tests
test angular ... bench: 31,115,052 ns/iter (+/- 1,265,163) = 23 MB/s
test angular_ts ... bench: 32,343,882 ns/iter (+/- 862,398) = 22 MB/s
test backbone ... bench: 4,069,784 ns/iter (+/- 322,482) = 14 MB/s
test backbone_ts ... bench: 4,242,501 ns/iter (+/- 592,016) = 14 MB/s
test colors ... bench: 51,999 ns/iter (+/- 12,837) = 22 MB/s
test colors_ts ... bench: 53,359 ns/iter (+/- 5,282) = 21 MB/s
test jquery ... bench: 24,954,176 ns/iter (+/- 1,207,941) = 10 MB/s
test jquery_mobile ... bench: 41,242,172 ns/iter (+/- 833,360) = 10 MB/s
test jquery_mobile_ts ... bench: 41,527,312 ns/iter (+/- 935,822) = 10 MB/s
test jquery_ts ... bench: 24,565,976 ns/iter (+/- 664,778) = 10 MB/s
test large ... bench: 709,609 ns/iter (+/- 207,575) = 7 MB/s
test mootools ... bench: 18,688,197 ns/iter (+/- 3,951,869) = 8 MB/s
test mootools_ts ... bench: 19,808,024 ns/iter (+/- 873,979) = 8 MB/s
test underscore ... bench: 3,398,891 ns/iter (+/- 255,715) = 12 MB/s
test underscore_ts ... bench: 3,632,732 ns/iter (+/- 183,886) = 11 MB/s
test yui ... bench: 17,540,363 ns/iter (+/- 683,704) = 19 MB/s
test yui_ts ... bench: 18,607,831 ns/iter (+/- 1,143,203) = 18 MB/s
test result: ok. 0 passed; 0 failed; 0 ignored; 17 measured; 0 filtered out
Less dependencies
swc_common
tty-emiiter(To remove tty related stuffs )sourcemap(To remove sourcemap for web assets)swc_ecma_parser:
swc_ecma_utils:
testing:
swc:
swc_ecmascript
It contains
ast,codegen,parser,utils,visit.