Skip to content

Conversation

@kdy1
Copy link
Member

@kdy1 kdy1 commented Jul 28, 2020

Comments refinement

Comments is now trait and swc_common only contains single-threaded Comments impl.
This allow dropping dependency on dashmap.

Multi-threaded implementation of Comments will live in the swc crate.

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, GLOBALS issue

This is about making swc_common::GLOBALS not 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 /Users/kdy1/projects/master-swc/target/release/deps/lexer-a67dc5a3727da1b3

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 /Users/kdy1/projects/master-swc/target/release/deps/parser-a03b4a2703c51f27

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 /Users/kdy1/projects/swc/target/release/deps/lexer-91bd039baebdb422

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 /Users/kdy1/projects/swc/target/release/deps/parser-3205c5afd12a24fc

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

  • Cargo feature tty-emiiter (To remove tty related stuffs )
  • Cargo feature sourcemap (To remove sourcemap for web assets)
  • Removed dependency on dashmap

swc_ecma_parser:

  • Removed dependency on once_cell and regex

swc_ecma_utils:

  • Removed dependency on parser

testing:

  • Remove dependency on relative_path

swc:

  • Remove dependency on derive_more and path-clean

swc_ecmascript

It contains ast, codegen, parser, utils, visit.

@kdy1 kdy1 marked this pull request as draft July 28, 2020 10:35
@kdy1 kdy1 force-pushed the crate-ux branch 3 times, most recently from 9ce0162 to b629cda Compare July 29, 2020 05:59
@kdy1 kdy1 self-assigned this Jul 29, 2020
@kdy1 kdy1 added this to the v1.2.10 milestone Jul 29, 2020
@kdy1 kdy1 changed the title UX for rust users Improve ux for rust users Jul 29, 2020
@kdy1 kdy1 modified the milestones: v1.2.10, v1.2.11 Jul 29, 2020
Comment on lines 193 to 195
fn take_leading(&self, pos: BytePos) -> Option<Vec<Comment>> {
(**self).take_leading(pos)
}
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

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 👍

@kdy1
Copy link
Member Author

kdy1 commented Jul 31, 2020

cc @ry @bartlomieju as I'm almost done.

I'll add more span tests via other prs.

@kdy1 kdy1 marked this pull request as ready for review July 31, 2020 09:48
@kdy1 kdy1 merged commit 0ac55ae into swc-project:master Jul 31, 2020
@kdy1 kdy1 deleted the crate-ux branch July 31, 2020 09:49
/// [&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
Copy link
Contributor

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.

Copy link
Member Author

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.

@swc-project swc-project locked as resolved and limited conversation to collaborators Nov 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate comment entries in CommentMap Add test for node text?

3 participants