Skip to content

perf(move-file): memoize common path operations #154

@LayZeeDK

Description

@LayZeeDK

Summary

Add lightweight memoization for frequently repeated path operations used by the move-file generator.

Proposed Solution

const pathOperationCache = {
  dirname: new Map<string, string>(),
  basename: new Map<string, string>(),
  relative: new Map<string, string>(),
};

function memoizedDirname(filePath: string): string {
  let result = pathOperationCache.dirname.get(filePath);
  if (result === undefined) {
    result = path.dirname(filePath);
    pathOperationCache.dirname.set(filePath, result);
  }
  return result;
}

// Implement similar helpers for basename and relative with composite keys.
  • Wrap hot path helpers with memoized versions.
  • Reset caches between generator executions to avoid stale values.

Tasks

  • Introduce memoized wrappers for the relevant path helpers
  • Replace hot-path usages in the generator with the memoized versions
  • Ensure the caches are cleared between generator executions to avoid stale data

Definition of Done

  • Existing benchmark and stress test suites are run before and after the change; document the measurements in the PR description. This is non-optional.
  • Unit/e2e tests must pass.
  • Update comments if the memoization layer needs clarification.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: lowLower priority performance optimization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions