Skip to content

perf(move-file): cache index file export analysis #161

@LayZeeDK

Description

@LayZeeDK

Summary

Cache export information for index files so isFileExported() and related checks avoid reparsing the same files during a batch move.

Proposed Solution

interface IndexExports {
  exports: Set<string>;
  reexports: Set<string>;
}

const indexExportsCache = new Map<string, IndexExports>();

function getIndexExports(tree: Tree, indexPath: string): IndexExports {
  const cached = indexExportsCache.get(indexPath);
  if (cached !== undefined) {
    return cached;
  }

  const exports = new Set<string>();
  const reexports = new Set<string>();

  const ast = astCache.getAST(tree, indexPath);
  if (ast) {
    // Parse and extract all exports
    // ... parsing logic ...
  }

  const result = { exports, reexports };
  indexExportsCache.set(indexPath, result);
  return result;
}
  • Cache parsed export lists for index/barrel files.
  • Consult the cache before re-parsing index files.

Tasks

  • Create an IndexExports cache keyed by normalized index file paths
  • Populate the cache via existing AST/content helpers on first access
  • Update export-checking utilities to consult the cache before re-reading

Definition of Done

  • Existing benchmark and stress test suites are run before and after the change; share the comparison in the PR description. This step cannot be skipped.
  • Unit/e2e tests must still pass.
  • Add inline docs describing the cache lifecycle if helpful.

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