Skip to content

Per-session env cache means every new shell pays a full rebuild — proposal: machine-global shared env output cache #694

Description

@xooooooooox

Follow-up to #690 / #691 (deterministic output order — this proposal builds on top of it).

Problem

env-state.json lives in the per-session temp dir (tmp/<date>-<pid>/), so a brand-new shell always starts cold: its first two hook runs do full rebuilds (every plugin's EnvKeys lua evaluation; two rounds are needed to reach the PATH fixed point). The cost scales with plugin count — and worse, any plugin that touches the network while loading turns every new terminal into a network-bound operation. Example: vfox-ruby fetches a GitHub manifest at require time, adding 0.3–1.2s per rebuild through a proxy, or hanging vfox activate entirely when the network path black-holes (see #693).

Measured with 7 plugins installed: pure lua rebuild ≈ 30ms; with vfox-ruby's manifest fetch ≈ 1.2s per new session; with a black-holed proxy: indefinite hang (>60s, killed manually).

Proposal: a second-level, machine-global, content-addressed cache

Consulted between the session fast path and the full rebuild:

  • Key = SHA-256 of (vfox version, shell name, raw $PATH, global config path+mtime, project config path+mtime) — exactly the inputs HasChanged already checks.
  • Strict sharing eligibility so session semantics are untouched:
    • sessions with a session-scope config never read or write shared entries;
    • outputs referencing the session shim dir are never published;
    • legacy-version-file setups are excluded;
    • degraded rebuilds (any SDK failing plugin load / symlink / EnvKeys) are never published.
  • Entries written atomically (temp file + rename), verified against the full serialized key on lookup, pruned on the existing daily CleanTmp cadence (30-day TTL, 256-entry cap).
  • Depends on fix(env): merge SDK envs in deterministic order to stabilize PATH and env-state cache #691: without deterministic output the keys never converge.

Working implementation

Running locally for a while now: xooooooooox@0a74b7c (branch patched-v1.0.11, +472 lines incl. unit tests). Result: new-session first hook run 1.2s → 22ms; cache hits skip plugin loading entirely, so shells stay responsive even when a plugin's network dependency is down.

Happy to adapt this into a PR if the direction works for you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions