mirror of
https://github.com/colbymchenry/codegraph.git
synced 2026-11-14 22:43:17 +08:00
perf(resolution): read a bare JS/TS call's local binding once per match — graph byte-identical
matchByExactName asked isLocallyBoundJsName for every cross-file candidate of a bare JavaScript or TypeScript call, though the answer depends only on the reference's name and file, which are the same for every candidate. The helper memoizes it per file and name, but each call still built the key and read the memo. The answer is now kept in a lazy local for the one match, at the same place in the filter, so candidates, order, scoring and confidence are untouched. Validation: fresh indexes of codegraph's own source, excalidraw, vben, express and zod dump byte-identical to main's (nodes, edges with their metadata, unresolved refs, files), and express stays identical through sync after a JS file is added, edited and deleted. A CPU profile of indexing codegraph's own source (all threads, two runs per side) puts isLocallyBoundJsName's self time at 150-173 ms on main and 45-46 ms here; the scans it guards (bindsAtSites) are unchanged. Whole-index CPU on vben, 10 interleaved runs, moves less than its noise. The PR's 8 tests pin the matcher's behaviour and pass here and on main. Original PR #2871 by @luojiyin1987. Fixes #2870 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Colby Mchenry
co-authored by
Claude Opus 5.5
parent
2afee00cb0
commit
0174f804c3
@@ -11866,6 +11866,8 @@ export function matchByExactName(
|
||||
const inheritanceRef = isInheritanceRef(ref);
|
||||
// Read once, and only for a candidate in another file: it scans the file.
|
||||
let bareTypeName: boolean | undefined;
|
||||
// Every candidate uses the same binding key. Keep this check lazy.
|
||||
let locallyBoundJsName: boolean | undefined;
|
||||
const tsBareTypeName = (): boolean => (bareTypeName ??= isTsBareTypeName(ref, context));
|
||||
const sameName = outOfRepoCall
|
||||
? innerScopeShadows(context.getNodesByName(ref.referenceName), ref, context)
|
||||
@@ -12008,7 +12010,7 @@ export function matchByExactName(
|
||||
!ESM_FAMILY.has(n.language) || !isSealedModule(n.filePath, context)) &&
|
||||
// A name the file binds itself (a parameter, a const) shadows every other
|
||||
// file's symbol of that name, so a bare call has no cross-file candidate.
|
||||
!(bareJs && n.filePath !== ref.filePath && isLocallyBoundJsName(ref.referenceName, ref.filePath, context))
|
||||
!(bareJs && n.filePath !== ref.filePath && (locallyBoundJsName ??= isLocallyBoundJsName(ref.referenceName, ref.filePath, context)))
|
||||
);
|
||||
const ranked = dartBare ? nearestDartMembers(preferOwnDartLibrary(filtered, ref, context), ref, context)
|
||||
: dartTypeRef && dartPrefix === null ? preferOwnDartLibrary(filtered, ref, context)
|
||||
|
||||
Reference in New Issue
Block a user