Skip to content

Conversation

LingyuCoder
Copy link
Contributor

@LingyuCoder LingyuCoder commented Aug 5, 2025

Summary

This pull request is inspired by turbopack

  • Try to create native regex instead of regress regex which has poor performance
  • Remove algo and its fast path logic because native regex is fast enough

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@Copilot Copilot AI review requested due to automatic review settings August 5, 2025 10:52
Copy link

netlify bot commented Aug 5, 2025

Deploy Preview for rspack ready!

Name Link
🔨 Latest commit 85d2522
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6895b1270205cf0008696258
😎 Deploy Preview https://deploy-preview-11292--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions bot added release: performance release: performance related release(mr only) team The issue/pr is created by the member of Rspack. labels Aug 5, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a performance optimization by implementing a hybrid regex approach that attempts to create native Rust regex first before falling back to the existing regress-based implementation. The change restructures RspackRegex from a single implementation to an enum that can handle both native and regress regex variants.

  • Restructures RspackRegex as an enum with Regex (native) and Regress (fallback) variants
  • Implements native regex creation with proper flag handling and error fallback
  • Updates API consumers to use accessor methods instead of direct field access

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

File Description
crates/rspack_regex/src/lib.rs Core refactoring to enum-based approach with native regex priority
crates/rspack_regex/src/napi.rs Updates to use accessor methods for flags and source
crates/rspack_regex/Cargo.toml Adds regex dependency for native implementation
crates/rspack_binding_api/src/raw_options/raw_builtins/raw_lazy_compilation.rs Updates to use accessor methods

@LingyuCoder LingyuCoder marked this pull request as draft August 5, 2025 10:56
Copy link
Contributor

github-actions bot commented Aug 5, 2025

📦 Binary Size-limit

Comparing 85d2522 to feat: move experiments.lazyCompilation to configuration toplevel (#11337) by qixuan

❌ Size increased by 142.25KB from 47.64MB to 47.78MB (⬆️0.29%)

Copy link

codspeed-hq bot commented Aug 5, 2025

CodSpeed Performance Report

Merging #11292 will not alter performance

Comparing perf/native-regex-first (85d2522) with main (f0cf886)

🎉 Hooray! codspeed-node just leveled up to 4.0.1!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

✅ 17 untouched benchmarks

@LingyuCoder LingyuCoder force-pushed the perf/native-regex-first branch from 76c0890 to c65ed39 Compare August 8, 2025 06:47
@LingyuCoder LingyuCoder changed the title perf: create native regex first perf: try to create native regex instead of regress Aug 8, 2025
@LingyuCoder LingyuCoder changed the title perf: try to create native regex instead of regress perf: try to create native regex instead of regress regex Aug 8, 2025
@LingyuCoder LingyuCoder force-pushed the perf/native-regex-first branch from a348c67 to 28dd463 Compare August 8, 2025 07:14
Copy link
Contributor

github-actions bot commented Aug 8, 2025

📝 Benchmark detail: Open

Name Base (2025-08-08 61153d6) Current Change
10000_big_production-mode_disable-minimize + exec 29.4 s ± 935 ms 29.7 s ± 820 ms +1.21 %
10000_development-mode + exec 1.77 s ± 59 ms 1.72 s ± 38 ms -3.04 %
10000_development-mode_hmr + exec 684 ms ± 11 ms 682 ms ± 9 ms -0.26 %
10000_development-mode_noop-loader + exec 2.62 s ± 121 ms 2.65 s ± 46 ms +1.26 %
10000_production-mode + exec 1.79 s ± 98 ms 1.75 s ± 100 ms -2.23 %
10000_production-mode_persistent-cold + exec 1.94 s ± 50 ms 1.94 s ± 60 ms +0.05 %
10000_production-mode_persistent-hot + exec 1.39 s ± 31 ms 1.6 s ± 64 ms +14.89 %
arco-pro_development-mode + exec 1.78 s ± 45 ms 1.78 s ± 57 ms 0.00 %
arco-pro_development-mode_hmr + exec 365 ms ± 0.74 ms 365 ms ± 0.76 ms +0.18 %
arco-pro_production-mode + exec 3.27 s ± 108 ms 3.27 s ± 76 ms +0.09 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.39 s ± 220 ms 3.35 s ± 124 ms -1.14 %
arco-pro_production-mode_persistent-cold + exec 3.39 s ± 62 ms 3.41 s ± 58 ms +0.67 %
arco-pro_production-mode_persistent-hot + exec 1.99 s ± 94 ms 2.05 s ± 22 ms +3.24 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.29 s ± 72 ms 3.3 s ± 56 ms +0.36 %
large-dyn-imports_development-mode + exec 1.91 s ± 44 ms 1.94 s ± 132 ms +1.64 %
large-dyn-imports_production-mode + exec 1.88 s ± 17 ms 1.89 s ± 24 ms +0.23 %
threejs_development-mode_10x + exec 1.53 s ± 108 ms 1.51 s ± 28 ms -1.23 %
threejs_development-mode_10x_hmr + exec 909 ms ± 22 ms 903 ms ± 2.5 ms -0.74 %
threejs_production-mode_10x + exec 4.64 s ± 302 ms 4.63 s ± 179 ms -0.25 %
threejs_production-mode_10x_persistent-cold + exec 4.69 s ± 33 ms 4.77 s ± 291 ms +1.71 %
threejs_production-mode_10x_persistent-hot + exec 4.11 s ± 67 ms 4.25 s ± 221 ms +3.48 %
10000_big_production-mode_disable-minimize + rss memory 9812 MiB ± 225 MiB 9975 MiB ± 208 MiB +1.66 %
10000_development-mode + rss memory 684 MiB ± 10.9 MiB 757 MiB ± 82.8 MiB +10.75 %
10000_development-mode_hmr + rss memory 837 MiB ± 53.3 MiB 877 MiB ± 26.2 MiB +4.74 %
10000_development-mode_noop-loader + rss memory 1028 MiB ± 40.2 MiB 1045 MiB ± 40.7 MiB +1.57 %
10000_production-mode + rss memory 654 MiB ± 17.6 MiB 735 MiB ± 27.6 MiB +12.48 %
10000_production-mode_persistent-cold + rss memory 772 MiB ± 60.1 MiB 845 MiB ± 50.2 MiB +9.39 %
10000_production-mode_persistent-hot + rss memory 752 MiB ± 50.8 MiB 908 MiB ± 50.2 MiB +20.67 %
arco-pro_development-mode + rss memory 632 MiB ± 34.6 MiB 657 MiB ± 16.7 MiB +3.97 %
arco-pro_development-mode_hmr + rss memory 538 MiB ± 13.8 MiB 537 MiB ± 41.7 MiB -0.03 %
arco-pro_production-mode + rss memory 764 MiB ± 155 MiB 752 MiB ± 50 MiB -1.57 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 749 MiB ± 62.2 MiB 794 MiB ± 73.2 MiB +5.95 %
arco-pro_production-mode_persistent-cold + rss memory 848 MiB ± 22.5 MiB 846 MiB ± 70.4 MiB -0.29 %
arco-pro_production-mode_persistent-hot + rss memory 684 MiB ± 56.9 MiB 700 MiB ± 59.2 MiB +2.31 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 733 MiB ± 47.3 MiB 741 MiB ± 83.6 MiB +1.02 %
large-dyn-imports_development-mode + rss memory 744 MiB ± 23 MiB 760 MiB ± 7.17 MiB +2.03 %
large-dyn-imports_production-mode + rss memory 644 MiB ± 15.4 MiB 661 MiB ± 11 MiB +2.66 %
threejs_development-mode_10x + rss memory 718 MiB ± 39.4 MiB 753 MiB ± 58.4 MiB +4.83 %
threejs_development-mode_10x_hmr + rss memory 949 MiB ± 56.5 MiB 948 MiB ± 56.4 MiB -0.06 %
threejs_production-mode_10x + rss memory 885 MiB ± 190 MiB 887 MiB ± 181 MiB +0.23 %
threejs_production-mode_10x_persistent-cold + rss memory 926 MiB ± 52.8 MiB 980 MiB ± 55.6 MiB +5.81 %
threejs_production-mode_10x_persistent-hot + rss memory 742 MiB ± 22 MiB 791 MiB ± 24.2 MiB +6.61 %

Threshold exceeded: ["10000_production-mode_persistent-hot + exec"]

// global: default in rust, ignore
'g' => {}
// case-insensitive: letters match both upper and lower case
'i' => applied_flags.push('i'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: performance release: performance related release(mr only) team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants