Skip to content

loadInstalledPluginIndexInstallRecordsSync runs on every resolvePluginTools call, including LRU cache hits #77348

Description

@jared-rebel

Summary

loadInstalledPluginIndexInstallRecordsSync({ env }) is called synchronously inside resolvePluginLoadCacheContext() on every invocation of resolvePluginTools(), including LRU cache hits. This adds unnecessary synchronous I/O to the hot path.

Root cause

function resolvePluginLoadCacheContext(options = {}) {
  // ...
  const installRecords = {
    ...loadInstalledPluginIndexInstallRecordsSync({ env }),  // sync I/O every call
    ...cfg.plugins?.installs
  };
  const cacheKey = buildCacheKey({ ..., installs: installRecords, ... });
  // cache lookup happens AFTER this
}

The install records are read to build the cache key before checking whether a cache hit exists. So even when PluginLoaderCacheState returns a warm entry in <10ms, the sync file read still fires.

Impact

  • Unnecessary sync I/O on every resolvePluginTools() call
  • Install records do not change at runtime — the read is always redundant after first call
  • Compounds under concurrent embedded runs where many crons fire simultaneously

Proposed fix

Memoize loadInstalledPluginIndexInstallRecordsSync result for the process lifetime (installs don't change while the gateway is running), or restructure so the cache key is computed only once per process startup and reused.

Related

Discovered alongside #77347 (workspaceDir in cache key).

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions