Skip to content

feat: support rspack native fs watcher #10658

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

Merged
merged 66 commits into from
Jul 15, 2025
Merged

feat: support rspack native fs watcher #10658

merged 66 commits into from
Jul 15, 2025

Conversation

GiveMe-A-Name
Copy link
Member

@GiveMe-A-Name GiveMe-A-Name commented Jun 13, 2025

Summary

Motivartion

This PR introduces a native file system watcher (NativeWatchFileSystem) to replace NodeWatchFileSystem when enabled via experiments.nativeWatcher: true. The goal is to:

Improve performance during mass file changes (fixing #7490).

Reduce Rspack’s JS/Rust boundary overhead by moving file watching to Rust.

Key Changes

  1. New Configuration Flag:
  • Adds experiments.nativeWatcher: bool to enable the feature.
  • Default: false (uses existing NodeWatchFileSystem).
  1. Implementation:
  • Path Manager: Computes files/folders to watch.
  • Analyzer: Builds a DirectoryTree to determine paths for notify (Rust lib).
  • Trigger: Translates filesystem events into rebuild triggers.
  • DiskWatcher: Monitors paths via notify and sends events to Trigger.
  • WatcherExecutor: Executes rebuilds after file changes.

Performance Benefits

Solves watchpack lag when handling large-scale file changes (e.g., git checkout, mass updates).

Rust-native efficiency: Leverages notify for low-overchange detection.

Usage

Enable in rspack.config.js:

experiments: {
  nativeWatcher: true // Opt-in to native watcher
}

Checklist

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

@GiveMe-A-Name GiveMe-A-Name self-assigned this Jun 13, 2025
Copy link

netlify bot commented Jun 13, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit a226310
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6874b4151a1eec00081b8816

@GiveMe-A-Name GiveMe-A-Name marked this pull request as draft June 13, 2025 02:45
@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Jun 13, 2025
- Updated `Cargo.toml` to include the "time" feature for Tokio.
- Refactored `WatcherDirectoriesAnalyzer` to use `WatchTarget` instead of `WatchInfo`.
- Introduced `Executor` struct to manage file system event handling and aggregation.
- Removed the old `WatcherExecutor` implementation and replaced it with the new `Executor`.
- Improved `DiskWatcher` to manage watched paths more effectively.
- Enhanced `Trigger` to facilitate dependency resolution for file system events.
- Updated the `FsWatcher` struct to integrate the new `Executor` and streamline event processing.
- Added detailed documentation for new and modified structs and methods.
- Removed the PathRegister and its associated logic, replacing it with PathManager to manage paths, directories, and missing paths.
- Introduced PathAccessor for accessing registered paths.
- Updated Analyzer trait to work with the new PathAccessor.
- Modified DiskWatcher to handle WatchPattern instead of raw paths.
- Enhanced Executor to manage event execution with aggregate handling.
- Updated NativeWatchFileSystem to include pause functionality and improved callback handling.
- Added tests for PathManager and related structures to ensure correct functionality.
Copy link

codspeed-hq bot commented Jun 26, 2025

CodSpeed Performance Report

Merging #10658 will improve performances by 21.32%

Comparing feat/native-watcher (a226310) with main (8bc3ece)

🎉 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

⚡ 1 improvements
✅ 15 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
js@is css mod 112.3 µs 92.6 µs +21.32%

@GiveMe-A-Name
Copy link
Member Author

📦 Binary Size-limit

Comparing 57db755 to chore(deps): update babel to ^7.28.0 (#10956) by renovate[bot]

❌ Size increased by 264.13KB from 59.50MB to 59.76MB (⬆️0.43%)

Testing in local, notify dependency will increment 200kb size on binary size
Other size increment maybe i open tokio time features and the watcher features code.
image

@GiveMe-A-Name GiveMe-A-Name requested a review from hardfist July 10, 2025 03:18
Copy link
Contributor

@stormslowly stormslowly left a comment

Choose a reason for hiding this comment

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

Could you please provide some performance comparasion data with watchpack ?

@GiveMe-A-Name
Copy link
Member Author

Could you please provide some performance comparasion data with watchpack ?

I do a watch diff in my local.

  • Native Watcher
image
  • Watchpack
image

stormslowly
stormslowly previously approved these changes Jul 11, 2025
Copy link
Contributor

github-actions bot commented Jul 14, 2025

📝 Ecosystem CI detail: Open

suite result
rsdoctor ✅ success
modernjs ❌ failure
devserver ✅ success
rsbuild ✅ success
rslib ✅ success
examples ✅ success
plugin ✅ success
lynx-stack ✅ success
rspress ✅ success
nuxt ✅ success

Copy link
Contributor

github-actions bot commented Jul 15, 2025

📝 Ecosystem CI detail: Open

suite result
rspress ✅ success
modernjs ✅ success
rsdoctor ✅ success
rslib ✅ success
nuxt ✅ success
examples ✅ success
devserver ✅ success
rsbuild ✅ success
lynx-stack ✅ success
plugin ✅ success

Copy link
Contributor

github-actions bot commented Jul 15, 2025

📝 Ecosystem CI detail: Open

suite result
rslib ✅ success
rsdoctor ✅ success
rsbuild ✅ success
rspress ✅ success
modernjs ✅ success
plugin ✅ success
devserver ✅ success
nuxt ✅ success
lynx-stack ✅ success
examples ✅ success

@hardfist hardfist merged commit b6ffa7d into main Jul 15, 2025
60 of 62 checks passed
@hardfist hardfist deleted the feat/native-watcher branch July 15, 2025 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: feature release: feature related release(mr only)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants