Skip to content

perf(write-bun-bin): bundle at build time and run the bundle from stdin - #1361

Closed
etrobert wants to merge 1 commit into
auto-brightness-bun-npmfrom
auto-brightness-bun-stdin
Closed

etrobert wants to merge 1 commit into
auto-brightness-bun-npmfrom
auto-brightness-bun-stdin

Conversation

@etrobert

Copy link
Copy Markdown
Owner

Stacked on #1353, to compare against #1354 (Node + zx).

Bun lists all of /nix/store (259,842 entries on tower) when it starts on a script stored there, oven-sh/bun#32389, or resolves an import from there. So every writeBunBin script took about 155 ms, whatever it does: strace shows 2,648 getdents64 calls on /nix/store/ per run. The same script copied to /tmp runs in 14 ms.

writeBunBin now:

Bundling alone (155 ms), a symlink outside the store (153 ms) and stdin without bundling (157 ms) all stay slow; only both together help.

hyperfine on tower, stub noctalia, 50 runs:

Mean
#1353, script in the store 156 ms
this PR 6.4 ms
#1354, Node + zx 44 ms

Trade-offs:

  • Scripts can no longer read their own stdin.
  • Error traces point to [stdin], not a file.
  • The bundle step also fails the build on an unresolved import (Could not resolve: "not-installed-pkg"), which the --no-bundle check missed. A syntax error still fails it (error: Unexpected ;).

Tested on tower: the table from #1353 under libfaketime, the real noctalia with the systemd unit's PATH (ok), and an invalid value, which surfaces noctalia's error. Both host toplevels build; nix fmt --ci and nix flake check --all-systems --no-build pass.

🤖 Generated with Claude Code

Bun lists all of /nix/store, 260k entries on tower, when it starts on a
script there (oven-sh/bun#32389) or resolves an import from there, so
every writeBunBin script took about 155 ms. Bundling at build time
leaves no import to resolve, and reading the bundle from stdin leaves
no script path: auto-brightness now runs in about 6 ms.

The bundle step also fails the build on an unresolved import, which
the --no-bundle check missed. Scripts can no longer read their own
stdin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@etrobert

Copy link
Copy Markdown
Owner Author

Closing in favour of #1354 (Node + zx), which was merged. Bun is dropped until oven-sh/bun#32389 is fixed.

@etrobert etrobert closed this Sep 28, 2026
@etrobert
etrobert deleted the auto-brightness-bun-stdin branch September 28, 2026 14:39
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