Skip to content

perf(secrets): batch mode for secret-cache-read (~15 ms fish-startup) (S-61)#83

Merged
tieubao merged 1 commit into
mainfrom
perf/secret-cache-batch
May 8, 2026
Merged

perf(secrets): batch mode for secret-cache-read (~15 ms fish-startup) (S-61)#83
tieubao merged 1 commit into
mainfrom
perf/secret-cache-batch

Conversation

@tieubao
Copy link
Copy Markdown
Member

@tieubao tieubao commented May 8, 2026

Summary

Adds secret-cache-read --batch VAR1 REF1 [VAR2 REF2 ...] mode that resolves N pairs in one bash invocation, emitting NUL-separated VAR\0VALUE pairs on stdout. Single batched call from secrets.fish.tmpl replaces 4 separate forks at every login fish startup.

Saves ~15 ms warm fish-startup on a 4-secret config (170 ms -> 155 ms across 5 cold-fish runs on Hans Air M4). The kernel security find-generic-password syscall itself is the irreducible cost; batching collapses bash-startup amortization (~3 ms × N). Honest measurement: originally predicted ~50 ms, actual is ~15 ms.

Replaces PR #78

PR #78 (perf/batch-secret-cache, drafted 2026-05-07) carried the same idea but couldn't rebase cleanly: main had evolved the single-pair script with negative-cache (24h TTL) and the -A flag for cross-Security-Session reads (S-51). Rather than wrestle a 4-way conflict, this is a fresh implementation merging both.

PR #77 was already closed as superseded (its SA-token-first reorder landed via commit 7c4ffc4).

Renumbering note

Originally drafted as S-55 on the old branch. Renumbered to S-61 to avoid colliding with S-55-claude-md-modify-idempotency shipped earlier today (v0.6.0).

Test plan

  • shellcheck --severity=warning home/dot_local/bin/executable_secret-cache-read clean
  • chezmoi execute-template < home/dot_config/fish/conf.d/secrets.fish.tmpl renders cleanly
  • fish -n clean on rendered template
  • chezmoi apply ~/.config/fish/conf.d/secrets.fish ~/.local/bin/secret-cache-read deploys
  • fish -l -c '...' populates all 4 secrets via new batched path: OP_SERVICE_ACCOUNT_TOKEN (860), CLOUDFLARE_API_TOKEN (53), R2_ACCESS_KEY_ID (32), R2_SECRET_ACCESS_KEY (64)
  • Negative-cache logic preserved (verified by code inspection)
  • -A flag for cross-Security-Session reads preserved (S-51)
  • SA-token-first ordering preserved via internal two-pass loop

🤖 Generated with Claude Code

… (S-61)

Adds `secret-cache-read --batch VAR1 REF1 [VAR2 REF2 ...]` mode that
resolves N pairs in one bash invocation, emitting NUL-separated
VAR\0VALUE pairs on stdout. Saves ~15 ms warm fish-startup on a
4-secret config (170 ms -> 155 ms across 5 cold-fish runs on
Hans Air M4). The kernel `security find-generic-password` syscall
itself is the irreducible cost; batching collapses bash-startup
amortization (~3 ms × N).

Internal two-pass loop resolves OP_SERVICE_ACCOUNT_TOKEN first so
subsequent op-read fallbacks have bearer auth in env (preserves the
SA-token-first ordering, mirrors the comment chain in the secrets.fish
template). The template no longer needs a conditional "load this var
first" block — ordering is the script's responsibility.

Refactor: introduces `_load_one` helper used by both single-pair and
batch modes. Keeps main's negative-cache (24h TTL) and `-A` flag for
cross-Security-Session reads (S-51).

`secrets.fish.tmpl` switches to one batched invocation, splits the
NUL-separated output via `string split0`, and `set -gx` each pair.

Renumbering note: this work was originally drafted as S-55 on
`perf/batch-secret-cache` (2026-05-07) but renumbered to S-61 to
avoid colliding with `S-55-claude-md-modify-idempotency` shipped
earlier today.

Verified on Mac mini: shellcheck clean, `fish -n` clean on rendered
template, all 4 secrets populate via the new path with non-empty
lengths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tieubao tieubao merged commit 73ea900 into main May 8, 2026
@tieubao tieubao deleted the perf/secret-cache-batch branch May 8, 2026 17:22
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