perf(rstest): minor performance optimization#12469
Conversation
✅ Deploy Preview for rspack canceled.
|
There was a problem hiding this comment.
Pull request overview
This PR implements several micro-optimizations to improve the performance of the rstest plugin by reducing redundant operations and memory allocations.
Key changes:
- Hoisted regex compilation to a static
LazyLockto avoid recompiling the same pattern on everyprocess_assetscall - Eliminated unnecessary string allocations in
calc_mocked_targetby using string slice operations instead of converting to owned strings - Pre-allocated Vec capacity based on chunk count to reduce reallocations during file collection
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/rspack_plugin_rstest/src/plugin.rs |
Moved regex compilation to static LazyLock and pre-allocated Vec capacity for file collection |
crates/rspack_plugin_rstest/src/parser_plugin.rs |
Reduced string allocations in calc_mocked_target by using &str operations and single-character pattern matching |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Rsdoctor Bundle Diff AnalysisFound 5 project(s) in monorepo. 📁 react-10kPath:
📦 Download Diff Report: react-10k Bundle Diff 📁 react-1kPath:
📦 Download Diff Report: react-1k Bundle Diff 📁 react-5kPath:
📦 Download Diff Report: react-5k Bundle Diff 📁 romePath:
📦 Download Diff Report: rome Bundle Diff 📁 ui-componentsPath:
📦 Download Diff Report: ui-components Bundle Diff Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
🎉 Size decreased by 256bytes from 48.28MB to 48.28MB (⬇️0.00%) |
CodSpeed Performance ReportMerging #12469 will not alter performanceComparing Summary
|
LazyLock will increase about 92KB binary size, which is too large. since it's not a hot code, we can keep the current code. |
Summary
Hoist regex compilation to static LazyLock to avoid recompiling on every process_assets callLazyLock will increase about 92KB binary size, which is too large. since it's not a hot code, we can keep the current code.
Reduce string allocations in calc_mocked_target by using &str operations instead of to_string()
Pre-allocate Vec capacity in mock_hoist_process_assets to avoid reallocations
Related links
Checklist