Skip to content

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

Merged
pi0 merged 2 commits intopithings:mainfrom
nicobailon:perf/macos-spawn-latency
Apr 8, 2026
Merged

perf: fix macOS spawn latency (~120ms → ~12ms)#1
pi0 merged 2 commits intopithings:mainfrom
nicobailon:perf/macos-spawn-latency

Conversation

@nicobailon
Copy link
Copy Markdown
Contributor

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.

nicobailon and others added 2 commits March 23, 2026 07:56
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.
Copy link
Copy Markdown
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thnx!! Sorry i missed this PR

@pi0 pi0 merged commit 1b97b51 into pithings:main Apr 8, 2026
3 checks passed
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.

2 participants