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
File diff suppressed because it is too large
Load Diff
@@ -18,6 +18,7 @@
|
||||
|
||||
mod buffers;
|
||||
mod ccpp;
|
||||
mod cfnptr;
|
||||
mod docstring;
|
||||
mod ids;
|
||||
mod go;
|
||||
@@ -98,6 +99,111 @@ pub fn grammar_info(language: String) -> Option<GrammarInfo> {
|
||||
})
|
||||
}
|
||||
|
||||
/// One struct node's extent for the cFnPtr sweep (mirror of the TS caller's
|
||||
/// `{ id, startLine, endLine }`, with `endLine ?? startLine` applied TS-side).
|
||||
#[napi(object)]
|
||||
pub struct CfnptrStructIn {
|
||||
pub id: String,
|
||||
pub start_line: u32,
|
||||
pub end_line: u32,
|
||||
}
|
||||
|
||||
#[napi(object)]
|
||||
pub struct CfnptrFileIn {
|
||||
/// RAW file text, exactly as the resolver's readFile returned it.
|
||||
pub text: String,
|
||||
pub structs: Vec<CfnptrStructIn>,
|
||||
}
|
||||
|
||||
#[napi(object)]
|
||||
pub struct CfnptrField {
|
||||
pub name: String,
|
||||
pub index: u32,
|
||||
pub ptr: bool,
|
||||
#[napi(js_name = "type")]
|
||||
pub ty: String,
|
||||
}
|
||||
|
||||
#[napi(object)]
|
||||
pub struct CfnptrStructOut {
|
||||
pub id: String,
|
||||
pub parsed: bool,
|
||||
pub fields: Vec<CfnptrField>,
|
||||
}
|
||||
|
||||
/// The cFnPtr extraction-sweep facts for one file — see cfnptr.rs (and the
|
||||
/// TS synthesizer's `FileFacts`) for field semantics.
|
||||
#[napi(object)]
|
||||
pub struct CfnptrFacts {
|
||||
pub fn_ptr_typedefs: Vec<String>,
|
||||
pub fn_type_typedefs: Vec<String>,
|
||||
pub structs: Vec<CfnptrStructOut>,
|
||||
pub inline_ptr: bool,
|
||||
pub inline_types: Vec<String>,
|
||||
pub inline_tags: Vec<String>,
|
||||
pub init_tokens: Vec<String>,
|
||||
pub array_elems: Vec<String>,
|
||||
pub alias_names: Vec<String>,
|
||||
pub d_pairs: Vec<String>,
|
||||
pub dispatch_fields: Vec<String>,
|
||||
pub array_dispatch_names: Vec<String>,
|
||||
pub includes: Vec<String>,
|
||||
}
|
||||
|
||||
/// Batched cFnPtr extraction sweep (task #5 step 2): one call scans a batch
|
||||
/// of files and returns their collected facts, amortizing the NAPI boundary.
|
||||
/// Feature-detected by the TS loader — absent on older binaries, where the
|
||||
/// synthesizer keeps its JS sweep.
|
||||
#[napi]
|
||||
pub fn cfnptr_scan_files(files: Vec<CfnptrFileIn>) -> Vec<CfnptrFacts> {
|
||||
files
|
||||
.into_iter()
|
||||
.map(|f| {
|
||||
let structs: Vec<cfnptr::StructExtent> = f
|
||||
.structs
|
||||
.into_iter()
|
||||
.map(|s| cfnptr::StructExtent { id: s.id, start_line: s.start_line, end_line: s.end_line })
|
||||
.collect();
|
||||
let facts = cfnptr::scan_file(&f.text, &structs);
|
||||
CfnptrFacts {
|
||||
fn_ptr_typedefs: facts.fn_ptr_typedefs,
|
||||
fn_type_typedefs: facts.fn_type_typedefs,
|
||||
structs: facts
|
||||
.structs
|
||||
.into_iter()
|
||||
.map(|s| CfnptrStructOut {
|
||||
id: s.id,
|
||||
parsed: s.parsed,
|
||||
fields: s
|
||||
.fields
|
||||
.into_iter()
|
||||
.map(|fl| CfnptrField { name: fl.name, index: fl.index, ptr: fl.ptr, ty: fl.ty })
|
||||
.collect(),
|
||||
})
|
||||
.collect(),
|
||||
inline_ptr: facts.inline_ptr,
|
||||
inline_types: facts.inline_types,
|
||||
inline_tags: facts.inline_tags,
|
||||
init_tokens: facts.init_tokens,
|
||||
array_elems: facts.array_elems,
|
||||
alias_names: facts.alias_names,
|
||||
d_pairs: facts.d_pairs,
|
||||
dispatch_fields: facts.dispatch_fields,
|
||||
array_dispatch_names: facts.array_dispatch_names,
|
||||
includes: facts.includes,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Debug/differential hook: the native `stripCommentsForRegex(text, 'c')`.
|
||||
/// Exists so the strip differential oracle can pin the Rust stripper against
|
||||
/// the TS reference directly.
|
||||
#[napi]
|
||||
pub fn cfnptr_strip_c(text: String) -> String {
|
||||
String::from_utf8_lossy(&cfnptr::strip_c(text.as_bytes())).into_owned()
|
||||
}
|
||||
|
||||
#[napi]
|
||||
pub fn extract_file(file_path: String, content: String, language: String) -> Result<ExtractBuffers> {
|
||||
let out = match language.as_str() {
|
||||
|
||||
Reference in New Issue
Block a user