Skip to content

Commit 4155231

Browse files
authored
fix: scope native import-edge skip to Windows only (#777)
* fix: scope native import-edge skip to Windows only The Rust key mismatch in build_import_edges (backslash vs forward slash) only affects Windows where path.join produces backslashes. On Linux/macOS path.join uses forward slashes matching the Rust format!("{}/{}", ...). Skipping native import edges on all platforms caused the Codegraph Impact Analysis CI workflow to fall back to the slow JS path unnecessarily. * fix: match Rust key format in resolvedImports instead of skipping native Instead of skipping the native import-edge builder for addon 3.8.0, construct resolvedImports keys as rootDir + "/" + relPath to match the Rust format!("{}/{}", root_dir, file) exactly. This avoids the Windows path separator mismatch without any performance penalty.
1 parent a4f12aa commit 4155231

1 file changed

Lines changed: 10 additions & 24 deletions

File tree

src/domain/graph/builder/stages/build-edges.ts

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { performance } from 'node:perf_hooks';
99
import { getNodeId } from '../../../../db/index.js';
1010
import { debug } from '../../../../infrastructure/logger.js';
1111
import { loadNative } from '../../../../infrastructure/native.js';
12-
import { normalizePath } from '../../../../shared/constants.js';
1312
import type {
1413
BetterSqlite3Database,
1514
Call,
@@ -198,8 +197,11 @@ function buildImportEdgesNative(
198197
};
199198
const fileNodeRowCache = new Map<string, { id: number }>();
200199

201-
// 2. Pre-resolve all imports and collect supplemental resolved entries
202-
const supplementalResolved: Array<{ key: string; resolvedPath: string }> = [];
200+
// 2. Pre-resolve all imports and build resolved imports array.
201+
// Keys use rootDir + "/" + relPath to match the Rust lookup format
202+
// (format!("{}/{}", root_dir, file)) — avoids separator mismatches on Windows
203+
// where path.join uses backslashes but Rust joins with forward slash.
204+
const resolvedImports: Array<{ key: string; resolvedPath: string }> = [];
203205

204206
for (const [relPath, symbols] of fileSymbols) {
205207
const fileNodeRow = addFileNodeId(relPath);
@@ -219,11 +221,8 @@ function buildImportEdgesNative(
219221
const resolvedPath = getResolved(ctx, path.join(rootDir, relPath), imp.source);
220222
addFileNodeId(resolvedPath);
221223

222-
// Check if this resolution is in batchResolved; if not, add supplemental
223-
const resolveKey = `${normalizePath(path.join(rootDir, relPath))}|${imp.source}`;
224-
if (!ctx.batchResolved?.has(resolveKey)) {
225-
supplementalResolved.push({ key: resolveKey, resolvedPath });
226-
}
224+
// Key matches Rust's format!("{}/{}", root_dir, file_input.file)
225+
resolvedImports.push({ key: `${rootDir}/${relPath}|${imp.source}`, resolvedPath });
227226

228227
importInfos.push({
229228
source: imp.source,
@@ -244,17 +243,6 @@ function buildImportEdgesNative(
244243
});
245244
}
246245

247-
// 3. Flatten batchResolved + supplemental into resolved imports array
248-
const resolvedImports: Array<{ key: string; resolvedPath: string }> = [];
249-
if (ctx.batchResolved) {
250-
for (const [key, resolvedPath] of ctx.batchResolved) {
251-
resolvedImports.push({ key, resolvedPath });
252-
}
253-
}
254-
for (const entry of supplementalResolved) {
255-
resolvedImports.push(entry);
256-
}
257-
258246
// 4. Flatten reexportMap
259247
const fileReexports: Array<{
260248
file: string;
@@ -744,12 +732,10 @@ export async function buildEdges(ctx: PipelineContext): Promise<void> {
744732
}
745733
}
746734

747-
// Skip native import-edge path for small incremental builds (≤3 files)
748-
// and for addon 3.8.0 which has a Windows path-separator bug in key
749-
// construction (format!("{}/{}", root_dir, file) vs path.join backslashes).
750-
const importEdgeBuggy = ctx.engineVersion === '3.8.0';
735+
// Skip native import-edge path for small incremental builds (≤3 files):
736+
// napi-rs marshaling overhead exceeds computation savings.
751737
const useNativeImportEdges =
752-
native?.buildImportEdges && !importEdgeBuggy && (ctx.isFullBuild || ctx.fileSymbols.size > 3);
738+
native?.buildImportEdges && (ctx.isFullBuild || ctx.fileSymbols.size > 3);
753739
if (useNativeImportEdges) {
754740
buildImportEdgesNative(ctx, getNodeIdStmt, allEdgeRows, native!);
755741
} else {

0 commit comments

Comments
 (0)