What Is Egonex importMap and How Pre-Resolution Optimizes the File Analyzer

Egonex importMap is a pre-computed lookup table that stores all import/export relationships discovered during an initial tree-sitter scan, allowing parallel file analyzers to skip re-parsing and directly build the dependency graph using pre-resolved data.

The Egonex importMap serves as the central nervous system for the Understand-Anything codebase analysis pipeline. In the Egonex-AI/Understand-Anything repository, this data structure captures every import statement across your project during a single static analysis pass. By pre-resolving these dependencies before parallel analysis begins, the system eliminates redundant parsing and provides deterministic graph construction.

Understanding the Egonex importMap Structure

The importMap is implemented as a Map<string, Set<string>> where each key represents an absolute file path and its corresponding value contains the complete set of import paths discovered within that file. During the scan phase located in understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.ts, the tree-sitter parser walks each source file and extracts import statements.

This structure is built once during the initial project scan and then frozen for the analysis phase. The map stores raw import paths as strings, maintaining the exact relationships discovered during static parsing without requiring additional resolution logic during graph construction.

How Pre-Resolution Optimizes the File Analyzer

Pre-resolution refers to the process of building the importMap during the scan phase and passing it as an immutable reference to parallel file-analyzer agents. This architectural decision provides three critical optimizations for the file analyzer.

Eliminating Redundant Parsing

Without pre-resolution, each parallel file analyzer would need to run its own tree-sitter instance to discover imports, creating O(n²) parsing complexity across n files. By passing the pre-computed importMap to the analyzer, each agent reads from the map directly rather than re-parsing source code. This reduces the per-file analysis phase to O(1) lookup operations.

Parallel Processing Benefits

The file analyzer agents operate concurrently using Promise.all(), with each agent receiving the shared importMap. As implemented in the codebase, the heavy lifting of parsing completes before parallel execution begins:

// Building the importMap during the scan phase
const importMap = new Map<string, Set<string>>()
for (const file of allFiles) {
  const imports = parseImportsWithTreeSitter(file.content)
  importMap.set(file.path, new Set(imports))
}

// Pass the map to parallel file analyzers
await Promise.all(
  files.map(f => fileAnalyzer.analyze(f, importMap))
)

This pattern ensures that CPU-intensive parsing happens sequentially (avoiding tree-sitter contention) while the lightweight analysis runs in parallel across all available cores.

Deterministic Graph Construction

The importMap guarantees reproducible graph edges across every execution. Because the same code always generates the same map entries, the GraphBuilder.addImportEdge() method creates consistent edges. The implementation in understand-anything-plugin/packages/core/src/analyzer/graph-builder.ts (lines 79-90) uses pre-resolved data to construct edges without dynamic resolution:

addImportEdge(fromFile: string, toFile: string): void {
  const key = `imports|file:${fromFile}|file:${toFile}`
  if (this.edgeKeys.has(key)) return          // dedupe
  this.edgeKeys.add(key)
  this.edges.push({
    source: `file:${fromFile}`,
    target: `file:${toFile}`,
    type: "imports",
    direction: "forward",
    weight: 0.7,
  })
}

The edge weight of 0.7 indicates the strength of the import relationship, while the deduplication check ensures no duplicate edges enter the graph.

Incremental Updates and Performance

The pre-resolved architecture supports incremental analysis workflows. When only a subset of files changes, the system updates the importMap entries for modified files while preserving unchanged entries. This allows the pipeline to re-analyze only modified files rather than triggering a full project scan.

The file analyzer in understand-anything-plugin/packages/core/src/analyzer/file-analyzer.ts consumes the importMap by reading the dependency set for its assigned file:

function analyze(file: File, importMap: Map<string, Set<string>>) {
  // No re-parsing required; direct lookup from pre-resolved map
  const deps = importMap.get(file.path) ?? new Set()
  for (const dep of deps) {
    graphBuilder.addImportEdge(file.path, dep)
  }
  // Continue with LLM-driven semantic analysis...
}

Summary

  • Egonex importMap is a Map<string, Set<string>> structure that stores pre-computed import relationships discovered by tree-sitter during the initial scan phase.
  • Pre-resolution eliminates redundant parsing by passing the completed importMap to parallel file analyzers, reducing per-file analysis to simple lookups.
  • The architecture provides deterministic graph construction through the addImportEdge() method in graph-builder.ts, ensuring reproducible dependency edges with a weight of 0.7.
  • Incremental updates are supported by updating only changed entries in the importMap, allowing selective re-analysis of modified files without full rescans.

Frequently Asked Questions

What data structure does Egonex importMap use?

The importMap uses a JavaScript Map where keys are file paths and values are Set<string> objects containing the import paths discovered in each file. This structure provides O(1) lookups and automatic deduplication of import statements within each file.

How does pre-resolution improve analysis speed?

Pre-resolution improves speed by performing tree-sitter parsing once during the scan phase rather than forcing each parallel analyzer to re-parse. This removes the CPU-intensive parsing bottleneck from the parallel analysis path, allowing file analyzers to focus on lightweight graph edge creation and LLM-driven semantic analysis.

Can the importMap handle incremental updates?

Yes. The importMap supports incremental updates by allowing the system to re-parse only modified files and update their specific entries. Unchanged files retain their existing import sets, enabling the pipeline to re-analyze only the affected subset of the codebase rather than performing a full project rescan.

Where is the importMap created in the codebase?

The importMap is created in understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.ts during the static analysis phase. It is then consumed by understand-anything-plugin/packages/core/src/analyzer/file-analyzer.ts and used by the GraphBuilder.addImportEdge() method in understand-anything-plugin/packages/core/src/analyzer/graph-builder.ts to construct the dependency graph.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →