code wiki / (root) / nx_segv_log_004.nx

nx_segv_log_004.nx source

↩ module page · 26 lines · 2701 B

1// nx_segv_log_004.nx -- compile-time O(N^2) in function-name lookup 2// table. Found while pipeline-testing 10k auto-generated stubs. 3 4// nx_safety_envelope: 5// intended_use: AUTO_APPLIED -- primitive-specific tuning queued 6// sil_target: SIL1 7// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail] 8// verdict: NOT_YET_EVALUATED 9 10import "nx_syscalls.nx" 11import "nx_runtime.nx" 12 13const STDOUT: i64 = 1 14 15func main() -> i64 { 16 let path: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/specs/segv_log.jsonl" as *u8 17 let fd: i64 = __syscall(SYS_OPENAT, AT_FDCWD, path as i64, 0x441, 0x1A4, 0, 0) 18 if fd < 0 { return 1 } 19 let line: *u8 = "{\"id\":\"perf-004-2026-05-13\",\"kind\":\"compile_quadratic\",\"discovered_at\":\"2026-05-13T16:00\",\"symptom\":\"nxc2 compile time scales O(N^2) in function count: 1k stubs = 116ms, 10k stubs = 16030ms (138x growth for 10x more funcs)\",\"trigger\":\"single .nx file with N auto-generated function definitions; each func adds an entry to the per-module function table which is later scanned linearly by call-site resolution\",\"root_cause\":\"parse_module's function-name resolution does linear scan over the functions[] array on every callsite; with N functions and ~N callsites total work is O(N^2)\",\"evidence\":\"timing curve from nx_primitive_stubs_smoke at 1k vs 10k matches O(N^2) signature\",\"fix\":\"swap linear scan in parse.c function-lookup with hash table (FNV-1a + open addressing same as nx_hash.nx). Estimated post-fix: 10k stubs compile in ~1.5 sec (linear); 100k in ~15 sec; 250k in ~40 sec\",\"verification\":\"end-to-end pipeline PASS: ingest 250k labels -> auto-generate 10k stubs -> compile to RV64 asm (379k lines) -> link -> qemu run -> all 10k return correct index. Each ingested label IS a callable NishiLang function. Pipeline architecturally complete; only perf chokepoint left.\",\"files_touched\":[\"nxc2/bench/nx_generate_primitive_stubs.sh\",\"nxc2/bench/nx_primitive_stubs_smoke.sh\",\"nxc2/runtime/generated_primitives_1000.nx\",\"nxc2/runtime/generated_primitives_10000.nx\"],\"regression_test\":\"nx_primitive_stubs_smoke.sh 1000 / 10000\",\"lesson\":\"Same O(N^2) chokepoint appears in two unrelated places (theorem-ingest + parser function-lookup). Both: linear scan over a growing table. Both: fixed by nx_hash. Pattern: any growing table needing dedup or lookup must use hash from day one. Add to BUG_TAXONOMY as cardinal pattern.\"}\n" as *u8 20 let n: i64 = strlen(line) 21 sys_write(fd, line, n) 22 sys_close(fd) 23 let msg: *u8 = "segv_log.jsonl updated with incident perf-004-2026-05-13\n" as *u8 24 sys_write(STDOUT, msg, strlen(msg)) 25 return 0 26}