-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Support @parcel/watcher #13593
Comments
We've discussed this before (Discord thread) and are open to trying it in Vite 5. The main blocker for me is that |
Vite should not depend on a C++ compiler being present as that is a major pain point for users. |
How so? Vite is already using esbuild. And has ecosystem support for SWC and lightningcss. |
@silverwind I think you misunderstood this comment. I guess you understood that comment as " |
Ah, so it is one big package of precompiled binaries with all os and archs in the package. Not ideal for install performance, but at least requires no install-time compilation, so it may be acceptable. |
Just for my curiosity, any reason for not considering Turbowatch? Mentioned in the original thread #12495 (comment) It uses |
From a maintenance standpoint, a pure JS module would be much better than C++ modules, which tend to require constant maintenance to not break because of ABI changes etc. It you check the issue tracker of parcel-bundler, there are a number of open issues about non-working platforms. |
That + it is very easy to add custom backends. Here is an example chokidar backend. The default backend basically checks if The other thing worth mentioning is that Turbowatch implements file hashing on top of file change triggers provided by the backend. In practice, we've found that this dramatically reduces the number of unnecessary re-renders as compared to mtime based systems. |
Releasing separate npm packages per platform has been on my list for
This particular change is very rare actually. Node-API is ABI stable, so should not break between versions of node. There are a few very obscure platforms that we haven't implemented backends for yet, or we need to provide pre-builds for so you don't need a compiler to install (once we have separate packages per platform this will be much easier), but in general it is very stable. It's exceedingly rare that an issue comes up that is caused by the watcher itself. Implementing low level stuff like this in compiled languages with deep integration into the OS provides a lot of benefits, especially in regards to performance (e.g. watching and debouncing occurs on a background thread).
|
Update: I've released |
I made two branches to test it out:
Made For |
The |
I did some work to support multiple threads over in parcel-bundler/watcher#146. There is an alpha version published if you want to try it out: v2.2.1-alpha.0. I ran the vite tests from your branch with this version and it seemed to work better. The remaining failures seem related an API change for the |
Thanks! I forgot to give an update that the I'm also curious on your thoughts if the |
Yeah it's probably not the most performant. On macOS it's probably fine, but on Linux there is a pretty low inotify watcher limit and watchers are not recursive by default so we have to traverse the directory hierarchy and watch each sub-directory manually. I noticed that you're calling If possible I'd recommend watching from the root of the project instead of watching each directory. You could also potentially use a similar interface to what you have but keep track of all the directories that were watched and find the minimal set of common root(s) between them to actually watch. We could potentially do something like that in |
It currently also adds the project vite/packages/vite/src/node/server/index.ts Line 356 in f385f20
So the @ArnaudBarre also had an idea that we only watch what's needed. For example, at the start we don't watch anything, but as we start to serve the app and crawl the transformed files, we add each of them to be watched. With the current |
Apologies for the delay! I have now released |
I've took another stab to use The wrapper to use |
@bluwy If compatibility with We've been using it now for ~7 months without an issue. |
Personally the package size is too big (though Vite bundle dependencies and I have not measured what the size would be). But it also depends on chokidar, and in that case it would be simpler if we use chokidar directly? It looks certainly robust but we're not going to use all of its features, and we usually try to balance the cost of functionality per package size in Vite. |
Interesting. Was not even aware of the package size. If Removing of the other dependencies though would be challenging without compromising the developer experience. Could maybe separate the core from the binary. Happy to explore if there is interest. |
1 and 2 is needed because we expose
|
Chokidar also supports glob pattern for file watch and To be fair though, it seems that the Chokidar author wanted to remove globs in this open Chokidar version 4 PR but I doubt it would be merge anytime soon since the PR is 1.5 year old at this point... which reminds me globs feature was removed from |
Yes, glob ignores are supported. They're pretty efficient too - they get compiled to a regex and matched in the C++ layer (off main thread). https://github.com/parcel-bundler/watcher#options |
Node just made native recursive watching available on Linux. It was originally added in Node 20, but had some bugs, so you couldn't use it just yet. It seems to be working now as of Node 20.13/22.1+. Perhaps |
We have already used the same OS APIs that node is using for years. Their implementation would be subject to the same OS limits. |
Ah, yeah. I guess you would need to implement |
This feels like probably too large of a barrier to me. Vite exposes chokidar's options, which means you would need to re-implement every single option that chokidar has. And it's also a bit constraining too - what if If we told people they needed to migrate from
Does chokidar support this? I didn't see that it did, but might have missed it
I guess this refers to having I found only one example of listening only to directory events: https://github.com/avisek/frontend-mentor-solutions/blob/8deb2852d58228a4dffe06d4653c8b8ceab904d0/vite.config.ts#L174 Listening only to file events happens more often, but I'm not sure if adding in directory events would harm anything in these use cases or not. E.g. with And |
I assume you made a typo and meant |
No, I actually meant |
Just so it's on the record: I am very open to adding new features to |
Someone else picked up that PR in paulmillr/chokidar#1304, which is being actively worked on, so it does look like glob support will probably be removed from chokidar soon |
I wonder in which ways
But is it worth adding all these native dependencies for Mac and Linux users? Why not just use the Node.js APIs on those platforms instead of needing a native distributable? |
same reasons you'd use chokidar: https://github.com/paulmillr/chokidar?tab=readme-ov-file#why
Generally more efficient: It is implemented natively, runs in a background thread, avoids crawling the file system on startup (see tweet linked above from when Nuxt switched), etc. See also: this issue on vscode which led to them switching away from chokidar. microsoft/vscode#3998 |
Re chokidar options, I mean it's exposed API instead, under Re non-recursive watching, chokidar supports this when you watch a single file, and only its directory is watched. Any recursive directories within it is not watched. This is commonly used for Also, (personally) And with chokidar v4 coming along (could propose changes), plus node constantly improving |
@devongovett what I meant is why doesn't I just looked through the two open issues linked to from the issue description and they don't really relate to what file watching library we use. One is about which files we should watch and the other is about the dev server hanging mostly related to circular dependencies or maybe too many open files (but not too many watched files). I'm wondering if anyone is even having issues with chokidar now at all or what the driving motivation for a switch would be. It would be helpful if there were some very large project we could test on where you could clearly see the difference between libraries. While some other projects have chosen |
Is there info on this somewhere? The v4 branch on the repo is over 2 years old.
It uses low level C APIs provided by the OS that Node doesn't use or expose. That's why it's more efficient. What's your motivation for commenting on this issue? You don't like native modules? FWIW, chokidar uses a native dependency too. Seems like you're interested in this space but if you're not having issues with chokidar then why get involved here?
There are clear issues that led to this being opened in the first place, and led others like Nuxt to switch. I don't use Vite so I'm sure others can speak to this better than me. I'm mainly here to help Vite adopt if they choose to. I have already put in a significant amount of work to help with this, including implementing several new features, as you can see in the thread. So far it has been deferred, but I remain available to help if needed. |
There was active discussion today about releasing chokidar v4 in the next month: paulmillr/chokidar#1304
Any details you can share? I'm curious which situations we'd see the performance differences
I'm a maintainer and want to ensure we're doing our due diligence in choosing whether to introduce breaking changes, native dependencies, etc.
I think that they can at times introduce an extra layer of complications. I know I've hit issues with sharp's on numerous occasions, but esbuild's have never caused much of an issue. I'm not really sure why they've caused me headaches in one situation and not the other, but it does seem like it would be nice to avoid if possible. We do use native dependencies already, so I'm not saying we can't use native dependencies, but I was interested to understand why they help since it seems like it's pretty much the same underlying API used (e.g.
I guess you're referring to
I definitely appreciate the willingness to help!! And to be clear I'm just one of many maintainers and not a core maintainer, so wouldn't want you implementing anything based off anything I've raised here. I think the Vite team as a whole should discuss whether we'd want to migrate and what the blockers would be so that we don't cause you any unnecessary work. |
Ok, here are the main things I am aware of in regards to performance:
In terms of reliability, I am aware that there have been some improvements to |
Thank you @devongovett!! This is really great information! (You should add it to the |
with a disadvantage of being a native module which doesn't run everywhere |
We've worked pretty hard to support as many platforms as possible. Is there one missing that you need? |
not really it’s that I maintain fsevents and through the years and nodejs updates some bug (incl compilation bug) somewhere will arise. so it needs to be constantly updated and supported. |
The response to the issue for the Windows user would be my # 1. The complete lack of maintenance for the last year would be my # 2. |
Description
Chokidar is slow and known to have issues with file descriptor limits when working with large projects. Parcel's watcher is much faster out of the box and additionally supports watchman as a backend, which improves support for Windows and minimizes overhead for projects already using watchman.
Nuxt recently added support for @parcel/watcher: nuxt/nuxt#20179
Suggested solution
Add option to use @parcel/watcher
Alternative
No response
Additional context
Related issues:
Twitter discussion https://twitter.com/patak_dev/status/1649060364431028226
Validations
The text was updated successfully, but these errors were encountered: