Description
watch
is deprecated per the watchman docs: https://facebook.github.io/watchman/docs/cmd/watch.html
it should be replaced with watch-project
: https://facebook.github.io/watchman/docs/cmd/watch-project.html
The latter has the big advantage of not creating redundant watches for subdirectories. When I looked at watchman watch-list
on my machine I had ~20 watches, all of which were subdirectories of my home directory. The daemon was using ~1.6GB of memory (I have about 1.5M files in my homedir).
I did watchman watch-del-all
, killed the daemon, then did watchman watch-project $HOME
, the current memory usage is 571MB.
The downside is you have to change how you do queries, you have to supply the "real" root returned from watch-project
and put the subdirectory in the expression
. It seems to me that watchman
could easily split the path itself to allow existing queries to continue to work.
So, for instance:
$ watchman watch-project $HOME
{
"version": "2022.06.13.00",
"watch": "/Users/todd",
"watcher": "fsevents"
}
$ watchman watch-project $HOME/subdir
{
"version": "2022.06.13.00",
"relative_path": "subdir",
"watch": "/Users/todd",
"watcher": "fsevents"
}
then, instead of using this query: ["query", "/Users/todd/subdir", { "expression": ["type", "f"], "fields": ["name"]}]
we have to do ["query", "/Users/todd", { "expression": ["allof", ["dirname", "subdir"], ["type", "f"]], "fields": ["name"]}]
and, annoyingly, strip subdir/
from the results.