Skip to content

SessionStart: fork tax -- $(config) x13, lib-slug sed build x22, log's printf|tr -- replace with builtins (Part of #660) #665

Closed

Description

@fdaviddpt

Part of #660.

Observed

Under MSYS fork is emulated, so a $( ) command substitution costs real time even when it wraps a builtin. The foreground SessionStart path carries roughly 60-70 such forks that exec nothing:

  • $(config key) x13 (log.sh:414,426,455,459,467,469, dispatch :1037,1040,1050, hook :696,902,978,999,1529). Each costs two forks: the substitution plus the ( LC_ALL=C; [[ … =~ … ]] ) subshell at log.sh:286. 26 forks.
  • lib-slug.sh:37-52 _remember_build_slug_sed: $(printf '\2xx') x22 to build the sed program. 22 forks, once per process -- and also once per PostToolUse hook.
  • log() (log.sh:532,553): $(_remember_date) + $(printf | tr) per call -- 2 forks + 1 exec every time anything logs.
  • 3x $(_remember_forward_slash), 4x $(_stdin_json_string), $(printf %q) at bootstrap-dirs.sh:169, two $(trap -p | sed) at lib-memory-dir.sh:356 / bootstrap-dirs.sh:200.

The repo already did this swap once: lib-clock.sh replaced date with bash's printf '%(FMT)T' builtin. This issue is the same move applied everywhere else on the hot path.

Cost

Estimated 0.6-2s per start on Windows/Git Bash (reasoned, not measured).

Fix shape

  • config_into VAR key default that assigns via printf -v and checks the key with a case glob (or saves/restores LC_ALL inline, as lib-slug.sh:321-326 already does) -- zero forks; migrate the 13 call sites.
  • Build _REMEMBER_SLUG_SED with $'\200' ANSI-C quoting: zero forks.
  • log: ${message//[[:cntrl:]]/ } instead of printf | tr; printf -v for the timestamp (lib-clock already offers _remember_date_into-style assignment at lib-clock.sh:119).
  • _remember_forward_slash, _stdin_json_string: add _into VAR variants using printf -v / parameter expansion.
  • $(trap -p | sed): capture with trap -p into a variable and strip with parameter expansion.

Positive control: existing slug/config/log tests unchanged; negative: a fork-count test (count $( substitutions executed via BASH_SUBSHELL/set -x trace, or strace -f -e fork where available) pinning the config path at zero forks.

[AI-generated]

Activity

  1. added
    priority:high
    filed-by-loop
    lane-capture
    on Sep 11, 2026
  2. self-assigned this
    on Sep 12, 2026
  3. removed their assignment
    on Sep 12, 2026
  4. added a commit that references this issue on Sep 25, 2026
  5. added 2 commits that reference this issue on Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    filed-by-looplane-capturepriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions