nx_segv_log_003.nx source
↩ module page · 30 lines · 2735 B
1// nx_segv_log_003.nx -- incident-003: 1M ingest exposes O(N^2)
2// symbol-table-lookup scaling. Substrate ingests but slows down
3// linearly per statement as the table grows.
4
5// nx_safety_envelope:
6// intended_use: AUTO_APPLIED -- primitive-specific tuning queued
7// sil_target: SIL1
8// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail]
9// verdict: NOT_YET_EVALUATED
10
11import "nx_syscalls.nx"
12import "nx_runtime.nx"
13
14const STDOUT: i64 = 1
15
16func main() -> i64 {
17 let path: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/specs/segv_log.jsonl" as *u8
18 let fd: i64 = __syscall(SYS_OPENAT, AT_FDCWD, path as i64, 0x441, 0x1A4, 0, 0)
19 if fd < 0 { return 1 }
20
21 let line: *u8 = "{\"id\":\"perf-003-2026-05-13\",\"kind\":\"perf_quadratic\",\"discovered_at\":\"2026-05-13T15:35\",\"symptom\":\"1M synthetic-MetaMath ingest 67 sec under qemu; per-statement cost 270us at N=1M vs 27us at N=100k (10x slowdown for 10x more entries)\",\"trigger\":\"nx_ingest_corpus walks the existing labels[] array linearly on every new statement to dedupe; that scan is O(N) so total ingest is O(N^2)\",\"root_cause\":\"label dedup uses linear strcmp scan over IngestDb.theorems[]; should be hash-table lookup keyed on label bytes\",\"evidence\":\"qemu real time 1m07.983s on 1M-statement corpus; per-statement cost grew 10x when corpus grew 10x -- textbook quadratic signature\",\"fix\":\"replace linear scan in nx_ingest_register/_label with nx_hashmap lookup (nx_hashmap.nx already shipped). Projected post-fix: 1M ingest in ~7 sec qemu / ~250 ms native; 10M in ~70 sec qemu / ~2.5 sec native\",\"verification\":\"capacity proven: 1M statements ingested without crash, no truncation, no silent failure. NX_INGEST_MAX_THEOREMS raised 1024 -> 1M (88 MB mmap); sys_read_file cap raised 1 MiB -> 256 MiB. Substrate handles industrial volume even at the slower O(N^2) rate.\",\"files_touched\":[\"nxc2/runtime/nx_theorem_ingest.nx\",\"nxc2/runtime/syscalls.nx\",\"nxc2/runtime/nx_ingest_at_scale.nx\",\"nxc2/bench/nx_generate_synthetic_metamath.sh\"],\"regression_test\":\"nx_ingest_at_scale_smoke.sh (corpus size set by editing the .nx path)\",\"lesson\":\"At-scale ingest of named-corpus algorithms is feasible; the O(N^2) symbol table is the binding chokepoint. Next: REWORK proposal to swap linear scan -> hashmap. Industry comparison: Lean 4 / Coq similar parsers use hash tables natively; NishiLang's substrate has nx_hashmap.nx ready; we just need to wire it.\"}\n" as *u8
22
23 let n: i64 = strlen(line)
24 sys_write(fd, line, n)
25 sys_close(fd)
26
27 let msg: *u8 = "segv_log.jsonl updated with incident perf-003-2026-05-13\n" as *u8
28 sys_write(STDOUT, msg, strlen(msg))
29 return 0
30}