Skip to content

perf(shim): add shim-to-runtime mapping cache for O(1) lookups#99

Merged
CalvinAllen merged 1 commit intomainfrom
perf/shim-map-cache
Dec 11, 2025
Merged

perf(shim): add shim-to-runtime mapping cache for O(1) lookups#99
CalvinAllen merged 1 commit intomainfrom
perf/shim-map-cache

Conversation

@CalvinAllen
Copy link
Contributor

Summary

  • Add persistent shim-to-runtime mapping cache (~/.dtvem/cache/shim-map.json)
  • Generate cache during reshim operations with runtime associations
  • Enable O(1) lookups in mapShimToRuntime() using cached map
  • Fix dynamic shim resolution for globally installed packages (tsc, eslint, black, etc.)

Problem

Previously, mapShimToRuntime() only knew about core provider shims (node, npm, python, pip, etc.). Dynamically installed packages like tsc (from TypeScript) or black (from pip) would fail with "runtime provider not found" because the fallback returned the shim name as the runtime name.

Solution

During reshim, we already scan each runtime's directories to find executables. Now we also build a mapping of shim → runtime and save it to ~/.dtvem/cache/shim-map.json:

{
  "node": "node",
  "npm": "node",
  "tsc": "node",
  "python": "python",
  "black": "python"
}

The shim executable loads this cache once (using sync.Once) for O(1) lookups.

Test plan

  • Unit tests for cache save/load functionality
  • Unit tests for LookupRuntime with cache hit/miss scenarios
  • Unit tests for sync.Once behavior (cache only loads once)
  • Manual testing: reshim generates cache file
  • Manual testing: core shims work (node, npm)
  • Manual testing: dynamic shims work (corepack)

Closes #93

Add a persistent shim-to-runtime mapping cache that enables O(1) lookups
and fixes dynamic shim resolution for globally installed packages.

Changes:
- Add cache directory to Paths struct (~/.dtvem/cache/)
- Generate shim-map.json during reshim operations
- Load cache in mapShimToRuntime() with sync.Once for efficiency
- Fall back to provider-based lookup if cache is missing

This fixes shims for dynamically installed packages (tsc, eslint, black,
pytest, etc.) which previously failed with "runtime provider not found"
because the fallback returned the shim name as the runtime name.

Closes #93

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@CalvinAllen CalvinAllen merged commit 24eb80f into main Dec 11, 2025
10 checks passed
@CalvinAllen CalvinAllen deleted the perf/shim-map-cache branch December 11, 2025 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

perf(shim): add shim-to-runtime mapping cache for O(1) lookups

1 participant