You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _blogposts/2025-11-11-introducing-rewatch.mdx
+23-6Lines changed: 23 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -237,15 +237,32 @@ The small cost of copying files upfront is paid back many times over through fas
237
237
238
238
### Wave-Based Parallel Compilation
239
239
240
-
ReWatch compiles your modules in dependency-order waves, with parallel processing within each wave.
240
+
ReWatch organizes compilation into waves based on dependencyorder. Think of it like an assembly line where some stations can run in parallel while others must wait for earlier stations to complete.
241
241
242
-
Here's how it works: modules with no pending dependencies compile first, in parallel. As they complete, the next wave of modules (whose dependencies are now satisfied) begins compiling. This continues until all modules are built.
242
+
Here's a concrete example. Imagine this dependency structure:
243
243
244
-
Combined with the CMI hash checking, this means:
244
+
```
245
+
A
246
+
╱ ╲
247
+
B C
248
+
│ │
249
+
D E
250
+
╲ ╱
251
+
F
252
+
```
253
+
254
+
ReWatch processes this in waves:
255
+
256
+
**Wave 1:** Compile A (no dependencies)
257
+
**Wave 2:** Compile B and C in parallel (both depend only on A, which is done)
258
+
**Wave 3:** Compile D and E in parallel (their dependencies are satisfied)
259
+
**Wave 4:** Compile F (waits for both D and E)
260
+
261
+
The key insight: within each wave, all modules compile simultaneously. ReWatch identifies which modules are ready (all their dependencies are compiled) and processes them together.
262
+
263
+
Combined with CMI hash checking, this becomes even more powerful. If module A's interface doesn't change, modules B and C might skip actual compilation even though they're queued in Wave 2. They pass through the wave without doing unnecessary work.
245
264
246
-
- Maximum parallelism within each wave
247
-
- Waves can terminate early if interface stability is detected
248
-
- No wasted work on modules that don't need rebuilding
265
+
This approach emerged naturally from solving the problem of "how do we compile as much as possible at once while respecting dependencies?" The solution turns out to be a classic computer science algorithm: [Kahn's algorithm](https://en.wikipedia.org/wiki/Topological_sorting#Kahn's_algorithm) for topological sorting. The beauty is that it's simply the optimal way to solve the problem, discovered independently by addressing the real-world constraints of module compilation.
0 commit comments