Skip to content

Commit b0faae6

Browse files
committed
Mention Kahn, but not his wrath
1 parent 9fc3dfe commit b0faae6

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

_blogposts/2025-11-11-introducing-rewatch.mdx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,32 @@ The small cost of copying files upfront is paid back many times over through fas
237237

238238
### Wave-Based Parallel Compilation
239239

240-
ReWatch compiles your modules in dependency-order waves, with parallel processing within each wave.
240+
ReWatch organizes compilation into waves based on dependency order. Think of it like an assembly line where some stations can run in parallel while others must wait for earlier stations to complete.
241241

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:
243243

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.
245264

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.
249266

250267
### Proper Monorepo Support
251268

0 commit comments

Comments
 (0)