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).
Summary
loadInstalledPluginIndexInstallRecordsSync({ env })is called synchronously insideresolvePluginLoadCacheContext()on every invocation ofresolvePluginTools(), including LRU cache hits. This adds unnecessary synchronous I/O to the hot path.Root cause
The install records are read to build the cache key before checking whether a cache hit exists. So even when
PluginLoaderCacheStatereturns a warm entry in <10ms, the sync file read still fires.Impact
resolvePluginTools()callProposed fix
Memoize
loadInstalledPluginIndexInstallRecordsSyncresult 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).