소스 검색

perf: Use indexed lookup in extractPascalDefProc instead of linear scan

Replace this.nodes.find() with a lazily-built Map<name, nodeId> for
matching implementation bodies to their declarations. Reduces per-file
complexity from O(methods × nodes) to O(nodes) for index build + O(1)
per lookup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Olaf Monien 4 달 전
부모
커밋
5a279d3132
1개의 변경된 파일11개의 추가작업 그리고 5개의 파일을 삭제
  1. 11 5
      src/extraction/tree-sitter.ts

+ 11 - 5
src/extraction/tree-sitter.ts

@@ -887,6 +887,7 @@ export class TreeSitterExtractor {
   private errors: ExtractionError[] = [];
   private extractor: LanguageExtractor | null = null;
   private nodeStack: string[] = []; // Stack of parent node IDs
+  private methodIndex: Map<string, string> | null = null; // name → node ID for defProc lookup
 
   constructor(filePath: string, source: string, language?: Language) {
     this.filePath = filePath;
@@ -2331,12 +2332,17 @@ export class TreeSitterExtractor {
     // fullName is like "TAuthService.Create" — we want just the method name part
     const shortName = fullName.includes('.') ? fullName.split('.').pop()! : fullName;
 
-    // Find matching node from earlier extraction
-    const existingNode = this.nodes.find(
-      (n) => n.name === shortName && (n.kind === 'method' || n.kind === 'function')
-    );
+    // Build method index on first use (O(n) once, then O(1) per lookup)
+    if (!this.methodIndex) {
+      this.methodIndex = new Map();
+      for (const n of this.nodes) {
+        if (n.kind === 'method' || n.kind === 'function') {
+          this.methodIndex.set(n.name, n.id);
+        }
+      }
+    }
 
-    const parentId = existingNode?.id || this.nodeStack[this.nodeStack.length - 1];
+    const parentId = this.methodIndex.get(shortName) || this.nodeStack[this.nodeStack.length - 1];
     if (!parentId) return;
 
     // Visit the block for calls