Skip to content

perf(move-file): cache relative import specifiers #158

@LayZeeDK

Description

@LayZeeDK

Summary

Cache the results of getRelativeImportSpecifier() so repeated file pair lookups reuse previously computed relative paths.

Proposed Solution

const relativePathCache = new Map<string, string>();

function getCachedRelativeImportSpecifier(
  fromFile: string,
  toFile: string,
): string {
  const cacheKey = `${fromFile}|${toFile}`;

  let result = relativePathCache.get(cacheKey);
  if (result === undefined) {
    result = getRelativeImportSpecifier(fromFile, toFile);
    relativePathCache.set(cacheKey, result);
  }

  return result;
}
  • Normalise file paths before building the cache key.
  • Clear the cache for every generator execution.

Tasks

  • Create a cache keyed by normalized file pair strings
  • Ensure all relative specifier calculations go through the cache helper
  • Clear the cache each generator execution to avoid stale paths

Definition of Done

  • Existing benchmark and stress test suites are run before and after the change; include the metrics in the PR description. This is a mandatory check.
  • Unit/e2e tests remain successful.
  • Document the cache behaviour if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumMedium priority performance optimization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions