Repository navigation
Commit 82d957f
authored
metro-file-map: Track only directories and symlinks in FallbackWatcher (#2107)
`FallbackWatcher` keeps an entry for every file it has seen:
https://github.com/react/metro/blob/56efab302200568c919ac1b3c28dacf8d84fc692/packages/metro-file-map/src/watchers/FallbackWatcher.js#L53-L56
It only reads them when something is deleted. Deleting `src/a.js` is reported because there's an entry for it, and deleting `src` reports `src/a.js`, `src/b.js` and so on from the entries, then `src` itself.
Neither needs an entry per file:
- A file's name says whether it was reported: `src/a.js` passes the include checks, `src/README.md` doesn't.
- Told that `src` is deleted, the file map removes everything under it (that's how `NativeWatcher` reports it), so one `delete` is enough.
So this keeps entries only for directories (including ones it couldn't watch) and symlinks. Those are reported whatever their name, so once `src/components` is gone, only an entry says whether it was a directory or a file the include checks left out.
## Benchmark
This takes another 22-30% off watch-mode startup on Linux and Windows (Linux: 969ms -> 695ms), and 3MB (10%) off the heap after startup on this app.
| | `main` | #2106 | This PR | vs `main` | vs #2106 |
|---|---|---|---|---|---|
| Linux: Watch-mode start, warm cache | 1,887ms | 969ms | 695ms | -63.2% (-63.6% to -62.8%) | -28.2% (-29.2% to -27.6%) |
| Windows: Watch-mode start, warm cache | 2,577ms | 935ms | 727ms | -71.8% (-71.9% to -71.7%) | -22.2% (-22.4% to -21.9%) |
| Linux: Watch-mode start, cold cache | 1,885ms | 931ms | 652ms | -65.4% (-65.6% to -65.1%) | -30.0% (-30.9% to -29.2%) |
| Windows: Watch-mode start, cold cache | 2,562ms | 917ms | 701ms | -72.7% (-72.8% to -72.5%) | -23.6% (-23.8% to -23.1%) |
| Linux: Heap after a watch-mode start | 31.7MB | 31.2MB | 28.1MB | -11.2% (-11.2% to -11.2%) | -9.9% (-9.9% to -9.9%) |
| Windows: Heap after a watch-mode start | 31.7MB | 31.3MB | 28.2MB | -11.3% (-11.3% to -11.3%) | -9.9% (-9.9% to -9.9%) |
## Changelog
```
- **[Performance]**: metro-file-map: Start the file watcher faster, and with less memory, on Linux and Windows without Watchman
```
## Test plan
New unit tests, and a `watch-integration-test.js` that drives FileMap in watch mode over a real directory, deleting directories and symlinks and moving directories out (with `FallbackWatcher`, or `NativeWatcher` on macOS). Benchmark as in #2104.1 parent d032fa5 commit 82d957f
5 files changed
Lines changed: 414 additions & 128 deletions
File tree
- packages/metro-file-map/src
- __tests__
- watchers
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
0 commit comments