Skip to content

perf: fix macOS spawn latency (~120ms → ~12ms)#1

Open
nicobailon wants to merge 1 commit intopithings:mainfrom
nicobailon:perf/macos-spawn-latency
Open

perf: fix macOS spawn latency (~120ms → ~12ms)#1
nicobailon wants to merge 1 commit intopithings:mainfrom
nicobailon:perf/macos-spawn-latency

Conversation

@nicobailon
Copy link

Hi! Just stumbled onto this:

macOS recently bumped sysconf(_SC_OPEN_MAX) to 1,048,575. closeExcessFds was calling close() from 3 to that limit in every child process — over a million no-op syscalls per spawn. Now we enumerate /dev/fd instead (same approach Linux uses with /proc/self/fd).

  BEFORE  spawn_to_first_ms: avg=119.0  p95=125.0
  AFTER   spawn_to_first_ms: avg=12.1   p95=13.5

Minor stuff: unref the Unix exit tsfn (Windows already did this), cache a TextDecoder in Terminal, and add scripts/bench-latency.ts.

Enumerate /dev/fd instead of brute-force close(3..sysconf limit),
which is ~1M no-op syscalls on modern macOS. Also unref Unix exit
tsfn to match Windows, cache TextDecoder, add latency benchmark.
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