perf(kernel): cFnPtr native extraction sweep — step 2, pass 230→151s across the arc (§7a.10) (#1365)
Task #5 step 2. The fuse-then-link refactor (#1364) left the extraction sweep as a clean per-file boundary: raw text in → collected facts out. This ports that sweep to the native kernel: `cfnptr_scan_files` (codegraph-kernel/src/cfnptr.rs) strips and scans a batch of 16 files per NAPI call, and the TS side only reads files, ships batches, interns the returned facts, and resolves include paths. The JS sweep remains as the fallback (no binary, feature detection against older binaries, CODEGRAPH_KERNEL=0, or CODEGRAPH_KERNEL_CFNPTR=0). Parity discipline: the JS regexes are the spec, so the scanners are hand-rolled byte machines reproducing that engine — ASCII \w/\b next to UNICODE \s (NBSP/U+2000-200A/FEFF decoded from UTF-8), alternation order, lastIndex resume, and the observable backtracking dimensions (INIT/ARRAY modifier and struct/star/bracket optionals, DISPATCH's greedy segment loop); greedy shortcuts only where backtracking provably can't rescue a match. The native stripper blanks per UTF-16 code unit, so its output is string-identical to the TS stripper — pinned by a new kernel arm on the strip differential oracle (fixtures + 500 seeded random cases). Gates, all green: new differential suite (adversarial fixture project — CRLF, NBSP, continuations, decoy strings, unterminated comments, backtracking shapes — indexed native-vs-JS: identical edge streams, plus a record-level scanner check); repo differential on git/redis/vim/SameBoy (identical, 705/852/433/180 edges); probe-hash on the live linux kernel DB reproduced f6e1713d… (279,335 rows); linux init counts exact 2,049,153/6,413,518; dump sha 6dd1185b… reproduced (10,446,478 lines); full suite green ×2 (153 files / 2588 tests). Measured (8c cg1212, quiet host): cFnPtr sub A=47.9s B=1.1 C=40.9 D=24.1 E=36.8 = 150.9s vs step 1's 179s and the pre-arc 230s (−34% cumulative); the sweep itself halved (94.5→47.9s, JS strips 132.4k→68.9k). callback-synthesis phase 199.9→171.1s. E's attributed wall grew from overlap shift under parallel synthesis; the phase total is the honest number. Full record: plan §7a.10. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
c6850d737b
commit
69ea438bac
@@ -53,10 +53,41 @@ export interface KernelGrammarInfo {
|
||||
fieldNames: string[];
|
||||
}
|
||||
|
||||
/** Input to the cFnPtr extraction sweep: one file's raw text + its struct
|
||||
* node extents (`endLine ?? startLine` applied by the caller). */
|
||||
export interface CfnptrFileIn {
|
||||
text: string;
|
||||
structs: { id: string; startLine: number; endLine: number }[];
|
||||
}
|
||||
|
||||
/** Per-file facts from the native cFnPtr extraction sweep — mirror of the
|
||||
* Rust `CfnptrFacts` (see codegraph-kernel/src/cfnptr.rs); semantics match
|
||||
* the JS sweep in src/resolution/c-fnptr-synthesizer.ts. */
|
||||
export interface CfnptrFactsOut {
|
||||
fnPtrTypedefs: string[];
|
||||
fnTypeTypedefs: string[];
|
||||
structs: { id: string; parsed: boolean; fields: { name: string; index: number; ptr: boolean; type: string }[] }[];
|
||||
inlinePtr: boolean;
|
||||
inlineTypes: string[];
|
||||
inlineTags: string[];
|
||||
initTokens: string[];
|
||||
arrayElems: string[];
|
||||
aliasNames: string[];
|
||||
dPairs: string[];
|
||||
dispatchFields: string[];
|
||||
arrayDispatchNames: string[];
|
||||
includes: string[];
|
||||
}
|
||||
|
||||
export interface KernelModule {
|
||||
extractFile(filePath: string, content: string, language: string): KernelBuffers;
|
||||
contractInfo(): KernelContractInfo;
|
||||
grammarInfo(language: string): KernelGrammarInfo | null;
|
||||
/** Batched cFnPtr extraction sweep (task #5 step 2). OPTIONAL: absent on
|
||||
* older binaries — callers feature-detect and keep their JS path. */
|
||||
cfnptrScanFiles?(files: CfnptrFileIn[]): CfnptrFactsOut[];
|
||||
/** Native `stripCommentsForRegex(text, 'c')` — differential-oracle hook. */
|
||||
cfnptrStripC?(text: string): string;
|
||||
}
|
||||
|
||||
const debugEnabled = () => process.env.CODEGRAPH_KERNEL_DEBUG === '1';
|
||||
|
||||
Reference in New Issue
Block a user