Skip to content

perf: wake the fs lock keep-alive thread immediately on release - #1317

Merged
dsherret merged 2 commits into
mainfrom
perf-lock-keepalive-exit
Oct 10, 2026
Merged

dsherret merged 2 commits into
mainfrom
perf-lock-keepalive-exit

Conversation

@dsherret

Copy link
Copy Markdown
Member

The keep-alive thread spawned by LaxSingleProcessFsFlag::lock slept for a flat 100ms between poll file updates and only checked the cancellation token after each sleep. The runtime waits for blocking tasks when the process shuts down, so on a cold plugin cache (where the lock is held while the plugin compiles) exiting was delayed until the thread's current sleep ended. In practice this quantized total process time to the keep-alive thread's 100ms boundaries.

This replaces the sleep with recv_timeout on an mpsc channel so that dropping the guard wakes the thread right away. The poll interval stays at 100ms since the other process treats the lock as abandoned after poll_file_update_ms * 2.

Confirmed with strace on the unmodified build: in runs where the lock was released just after a poll file write, exit_group happened exactly 100ms later.

Timings

Cold cache (DPRINT_CACHE_DIR pointing at an empty directory, deleted between runs), release build, dprint output-resolved-config with a config referencing a local typescript plugin .wasm file by path. hyperfine -N --warmup 2 --runs 20.

mean ± σ min … max
before 353.5 ms ± 72.3 ms 310.2 ms … 533.5 ms
after 283.8 ms ± 3.7 ms 278.8 ms … 297.4 ms

Sorted run times (ms):

before: 310 310 310 310 310 310 310 311 311 311 311 311 316 319 412 415 415 418 518 533
after:  279 281 281 282 282 282 283 283 283 283 283 284 284 284 284 285 285 286 287 297

@dsherret
dsherret merged commit 30971b0 into main Oct 10, 2026
17 checks passed
@dsherret
dsherret deleted the perf-lock-keepalive-exit branch October 10, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant