Skip to content
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

perf(atoms): Replace string-cache with hstr #8126

Merged
merged 23 commits into from Nov 7, 2023
Merged

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented Oct 15, 2023

Description:

hstr is an alternative for string-cache which does not support static strings and does not use a global mutex.

NOTE:
You must use AtomStore to create new Atoms. Otherwise it will be much slower.

Related issue:


Patch section

For convenience, I'm writing patch section here.

[patch.crates-io]
ast_node = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
better_scoped_tls = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
binding_macros = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
dbg-swc = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
from_variant = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
jsdoc = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
preset_env_base = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
string_enum = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_atoms = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_bundler = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_cached = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_cli_impl = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_common = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_compiler_base = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_config = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_config_macro = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_core = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_css = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_css_ast = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_css_codegen = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_css_codegen_macros = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_css_compat = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_css_lints = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_css_minifier = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_css_modules = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_css_parser = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_css_prefixer = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_css_utils = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_css_visit = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_ast = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_codegen = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_codegen_macros = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_compat_bugfixes = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_compat_common = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_compat_es2015 = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_compat_es2016 = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_compat_es2017 = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_compat_es2018 = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_compat_es2019 = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_compat_es2020 = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_compat_es2021 = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_compat_es2022 = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_compat_es3 = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_dep_graph = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_ext_transforms = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_lints = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_loader = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_minifier = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_parser = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_preset_env = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_quote = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_quote_macros = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_testing = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_transforms = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_transforms_base = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_transforms_classes = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_transforms_compat = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_transforms_macros = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_transforms_module = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_transforms_optimization = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_transforms_proposal = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_transforms_react = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_transforms_testing = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_transforms_typescript = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_usage_analyzer = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_utils = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecma_visit = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_ecmascript = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_eq_ignore_macros = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_error_reporters = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_estree_ast = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_estree_compat = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_fast_graph = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_graph_analyzer = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_html = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_html_ast = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_html_codegen = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_html_codegen_macros = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_html_minifier = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_html_parser = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_html_utils = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_html_visit = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_macros_common = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_node_base = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_node_bundler = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_node_comments = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_nodejs_common = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_plugin = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_plugin_macro = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_plugin_proxy = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_plugin_runner = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_plugin_testing = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_timer = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_trace_macro = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_visit = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_visit_macros = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_xml = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_xml_ast = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_xml_codegen = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_xml_codegen_macros = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_xml_parser = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
swc_xml_visit = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
testing = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }
testing_macros = { git = 'https://github.com/kdy1/swc.git', branch = "kdy-str" }

@kdy1 kdy1 self-assigned this Oct 15, 2023
@kdy1
Copy link
Member Author

kdy1 commented Oct 15, 2023

I also profiled non-interning string libraries.

single-thread/create/mixed/kdy_str/1024
                        time:   [216.84 ns 218.76 ns 221.02 ns]
                        change: [-2.1490% -0.9522% +0.1637%] (p = 0.13 > 0.05)
                        No change in performance detected.
Found 4 outliers among 100 measurements (4.00%)
  1 (1.00%) low mild
  2 (2.00%) high mild
  1 (1.00%) high severe
single-thread/create/mixed/string_cache/1024
                        time:   [333.78 ns 336.26 ns 338.91 ns]
Found 5 outliers among 100 measurements (5.00%)
  5 (5.00%) high mild
single-thread/create/mixed/compact_str/1024
                        time:   [4.5714 ns 4.6302 ns 4.7044 ns]
Found 9 outliers among 100 measurements (9.00%)
  1 (1.00%) low mild
  3 (3.00%) high mild
  5 (5.00%) high severe
single-thread/create/mixed/smartstring/1024
                        time:   [28.979 ns 29.251 ns 29.542 ns]
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high mild
single-thread/create/mixed/smol_str/1024
                        time:   [37.479 ns 37.616 ns 37.786 ns]
Found 8 outliers among 100 measurements (8.00%)
  7 (7.00%) high mild
  1 (1.00%) high severe
single-thread/create/mixed/kstring/1024
                        time:   [6.3936 ns 6.5561 ns 6.7090 ns]
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high mild
single-thread/create/mixed/kdy_str/2048
                        time:   [413.73 ns 415.99 ns 418.52 ns]
Found 7 outliers among 100 measurements (7.00%)
  5 (5.00%) high mild
  2 (2.00%) high severe
single-thread/create/mixed/string_cache/2048
                        time:   [629.17 ns 631.60 ns 634.07 ns]
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) high mild
  1 (1.00%) high severe
single-thread/create/mixed/compact_str/2048
                        time:   [5.4636 ns 5.5746 ns 5.7052 ns]
Found 9 outliers among 100 measurements (9.00%)
  1 (1.00%) low severe
  1 (1.00%) low mild
  3 (3.00%) high mild
  4 (4.00%) high severe
single-thread/create/mixed/smartstring/2048
                        time:   [48.763 ns 49.517 ns 50.350 ns]
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) high mild
  1 (1.00%) high severe
single-thread/create/mixed/smol_str/2048
                        time:   [54.564 ns 54.952 ns 55.438 ns]
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high mild
single-thread/create/mixed/kstring/2048
                        time:   [7.7745 ns 7.9686 ns 8.1736 ns]
Found 4 outliers among 100 measurements (4.00%)
  1 (1.00%) low mild
  2 (2.00%) high mild
  1 (1.00%) high severe

@kdy1
Copy link
Member Author

kdy1 commented Oct 15, 2023



Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.0s, or reduce sample count to 70.
single-thread/HashSet/kdy_str/1000
                        time:   [37.761 µs 38.952 µs 40.328 µs]
Found 9 outliers among 100 measurements (9.00%)
  2 (2.00%) low mild
  3 (3.00%) high mild
  4 (4.00%) high severe
Benchmarking single-thread/HashSet/string_cache/1000: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.6s, or reduce sample count to 60.
single-thread/HashSet/string_cache/1000
                        time:   [30.396 µs 31.017 µs 31.718 µs]
Found 5 outliers among 100 measurements (5.00%)
  3 (3.00%) high mild
  2 (2.00%) high severe
Benchmarking single-thread/HashSet/compact_str/1000: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.7s, or reduce sample count to 70.
single-thread/HashSet/compact_str/1000
                        time:   [1.7154 ms 1.7470 ms 1.7798 ms]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
Benchmarking single-thread/HashSet/smartstring/1000: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.7s, or reduce sample count to 70.
single-thread/HashSet/smartstring/1000
                        time:   [1.5879 ms 1.5932 ms 1.5995 ms]
Found 11 outliers among 100 measurements (11.00%)
  4 (4.00%) high mild
  7 (7.00%) high severe
Benchmarking single-thread/HashSet/smol_str/1000: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.8s, or reduce sample count to 70.
single-thread/HashSet/smol_str/1000
                        time:   [1.6879 ms 1.7071 ms 1.7296 ms]
Found 13 outliers among 100 measurements (13.00%)
  5 (5.00%) high mild
  8 (8.00%) high severe
Benchmarking single-thread/HashSet/kstring/1000: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.7s, or reduce sample count to 70.
single-thread/HashSet/kstring/1000
                        time:   [1.5927 ms 1.5980 ms 1.6046 ms]
Found 7 outliers among 100 measurements (7.00%)

@kdy1 kdy1 changed the title perf(atoms): Replace string-cache with kdy-str perf(atoms): Replace string-cache with hstr Oct 15, 2023
@kdy1
Copy link
Member Author

kdy1 commented Nov 4, 2023

Current main

    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `/Users/kdy1/projects/master-swc/target/debug/xtask bench -p swc_ecma_parser --bench parser angular`
Running RUST_LOG="off" "cargo" "bench" "--package" "swc_ecma_parser" "--bench" "parser" "--" "angular"
    Finished bench [optimized + debuginfo] target(s) in 0.21s
     Running benches/parser.rs (/Users/kdy1/projects/master-swc/target/release/deps/parser-26a0485ce6bcb9c0)
Gnuplot not found, using plotters backend
es/parser/angular       time:   [8.2907 ms 8.2971 ms 8.3045 ms]
                        change: [-0.2870% -0.1496% -0.0148%] (p = 0.03 < 0.05)
                        Change within noise threshold.
Found 16 outliers among 100 measurements (16.00%)
  6 (6.00%) high mild
  10 (10.00%) high severe

Empty static atom set

    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/xtask bench -p swc_ecma_parser --bench parser angular`
Running RUST_LOG="off" "cargo" "bench" "--package" "swc_ecma_parser" "--bench" "parser" "--" "angular"
    Finished bench [optimized + debuginfo] target(s) in 0.22s
     Running benches/parser.rs (target/release/deps/parser-26a0485ce6bcb9c0)
Gnuplot not found, using plotters backend
es/parser/angular       time:   [7.9108 ms 7.9265 ms 7.9466 ms]
                        change: [-0.6782% -0.2956% +0.0662%] (p = 0.14 > 0.05)
                        No change in performance detected.
Found 10 outliers among 100 measurements (10.00%)
  5 (5.00%) high mild
  5 (5.00%) high severe

hstr

    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running `/Users/kdy1/projects/s/perf/target/debug/xtask bench -p swc_ecma_parser --bench parser angular`
Running RUST_LOG="off" "cargo" "bench" "--package" "swc_ecma_parser" "--bench" "parser" "--" "angular"
    Finished bench [optimized + debuginfo] target(s) in 0.22s
     Running benches/parser.rs (/Users/kdy1/projects/s/perf/target/release/deps/parser-ec3fa4b53d07e2d7)
Gnuplot not found, using plotters backend
es/parser/angular       time:   [7.6656 ms 7.6822 ms 7.7014 ms]
                        change: [-0.0683% +0.1784% +0.4201%] (p = 0.19 > 0.05)
                        No change in performance detected.
Found 10 outliers among 100 measurements (10.00%)
  4 (4.00%) high mild
  6 (6.00%) high severe

@kdy1
Copy link
Member Author

kdy1 commented Nov 4, 2023

Minifier:

Current main

Gnuplot not found, using plotters backend
Benchmarking es/minify/libraries/antd: Warming up for 3.0000 s
Warning: Unable to complete 10 samples in 5.0s. You may wish to increase target time to 6.4s.
es/minify/libraries/antd
                        time:   [650.72 ms 652.33 ms 653.89 ms]
                        change: [-5.7943% -4.9956% -4.3358%] (p = 0.00 < 0.05)
                        Performance has improved.

Empty atom set

Gnuplot not found, using plotters backend
Benchmarking es/minify/libraries/antd: Warming up for 3.0000 s
Warning: Unable to complete 10 samples in 5.0s. You may wish to increase target time to 6.4s.
es/minify/libraries/antd
                        time:   [645.04 ms 646.84 ms 648.65 ms]

hstr


Gnuplot not found, using plotters backend
Benchmarking es/minify/libraries/antd: Warming up for 3.0000 s
Warning: Unable to complete 10 samples in 5.0s. You may wish to increase target time to 6.5s.
es/minify/libraries/antd
                        time:   [685.23 ms 688.49 ms 691.64 ms]
                        change: [-9.7953% -8.8707% -8.0907%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 10 measurements (10.00%)
  1 (10.00%) low mild

@kdy1 kdy1 force-pushed the kdy-str branch 2 times, most recently from 0a219a8 to 39782db Compare November 5, 2023 00:41
Copy link
Member Author

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

swc-bump:

  • swc_atoms

@kdy1 kdy1 requested a review from dsherret November 5, 2023 01:15
@kdy1 kdy1 marked this pull request as ready for review November 5, 2023 01:16
kodiakhq[bot]
kodiakhq bot previously approved these changes Nov 5, 2023
kodiakhq[bot]
kodiakhq bot previously approved these changes Nov 6, 2023
kodiakhq[bot]
kodiakhq bot previously approved these changes Nov 6, 2023
kodiakhq[bot]
kodiakhq bot previously approved these changes Nov 6, 2023
kodiakhq[bot]
kodiakhq bot previously approved these changes Nov 6, 2023
@kdy1 kdy1 enabled auto-merge (squash) November 7, 2023 00:36
@kdy1 kdy1 added this to the Planned milestone Nov 7, 2023
@kdy1 kdy1 merged commit aa22746 into swc-project:main Nov 7, 2023
142 checks passed
@kdy1 kdy1 deleted the kdy-str branch November 7, 2023 00:51
@kdy1 kdy1 modified the milestones: Planned, v1.3.97 Nov 9, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.97 Nov 20, 2023
@swc-project swc-project locked as resolved and limited conversation to collaborators Dec 21, 2023
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.

Use alternative string lib Use better string type
2 participants