Skip to content

perf(shim): optimize shim startup time and binary size #72

@CalvinAllen

Description

@CalvinAllen

Optimize shim execution for faster command invocation.

Problem

The shim binary is invoked on every node, npm, python, pip command. Current issues:

  • Binary size: ~10MB (same as main CLI)
  • Heavy dependencies: Pulls in net/http, progressbar, color libraries not needed at runtime
  • Expensive operations on every invocation:
    • Directory tree walking to find .dtvem/runtimes.json
    • JSON parsing of config files
    • Multiple os.Stat() calls per directory level
    • Runtime provider initialization

Performance Targets

  • Shim overhead: < 10ms
  • Binary size: < 5MB (ideally < 3MB)

Optimization Opportunities

Quick Wins

  • Strip debug symbols in builds (-ldflags="-s -w") - reduces ~30%
  • Cache os.UserHomeDir() - called multiple times
  • Don't import ui package in shim - use plain fmt.Fprintf

Medium Effort

  • Create shim-specific "lite" provider interface (only needs Name, Shims, ExecutablePath, IsInstalled, ShouldReshimAfter)
  • Remove HTTP/download dependencies from shim build
  • Cache resolved paths with mtime invalidation
  • Lazy-load providers - don't register until needed

Architecture Options (for discussion)

  • Build tags to exclude heavy code from shim
  • Separate lite provider package
  • Bake resolved paths at reshim time

Analysis

The shim imports full runtime providers which import:

  • net/http (~2MB) - for ListAvailable()
  • progressbar/v3 (~500KB) - via ui package
  • fatih/color (~200KB) - for colored output
  • download package - for installation

None of these are needed for shim's core job: resolve version → find executable → exec.

Related

Split from #19 to focus specifically on shim performance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions