code wiki / (root) / nx_perf_rehearsal.nx

nx_perf_rehearsal.nx source

↩ module page · 68 lines · 5068 B

1// nx_perf_rehearsal.nx -- THE MISSING FEEDBACK EDGE (operator 2026-06-23: "our analytics becomes a 2// feedback loop of s class exceed improving like the nishi conductor would do with the nishi orchestra"). 3// The rehearsal loop EXISTS but is CORRECTNESS-ONLY: nx_conductor_notes names the weakest section from 4// RED gate arcs (examiner_arcs.log); nx_woodshed drills a module until it builds clean. A capability that 5// is GREEN-BUT-SLOW (passes gates, LOSES the race on latency) is INVISIBLE to the teacher. This is the 6// adapter that feeds PERFORMANCE/RACE analytics (nx_apm_sweep latency, nx_diora_leaderboard BEHIND) INTO 7// the conductor's weakest-section call -- so the team drills what LOSES RACES, not just what is broken. 8// COMPOSES the conductor-notes idiom (extended gate-red -> perf-behind); does NOT duplicate it. No new 9// monitor/census. Routes a BEHIND to a sectional drill (the trainer); an EXCEED bumps readiness. 10// license_tier: ORIGINAL 11import "nx_syscalls.nx" 12import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 13const PR_MAGIC_1105: i64 = 1105 14 15const PR_LOG: *u8 = "knowledge/status/perf_rehearsal.log" 16 17func pr_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 18// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 19// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 20// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 21// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 22func pr_n(v: i64) -> i64 { nxi_out(v); return 0 } 23func pr_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){dst[off+i]=s[i];i=i+1} return off+i } 24func pr_catn(dst: *u8, off: i64, v: i64) -> i64 { var m: i64=v; var o: i64=off; if m<0{dst[o]=45 as u8;o=o+1;m=0-m} let t: *u8=sys_mmap(24); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{dst[o+i]=t[k-1-i];i=i+1} return o+k } 25 26// THE FEEDBACK EDGE: given an analytics result for a delivery capability (nishi vs incumbent metric, 27// lower_better=1 for latency), decide DRILL (we LOSE -> the conductor's weakest section) or EXCEED. 28// Emits the conductor-notes-style record to PR_LOG + stdout. Returns 1 if BEHIND (drill called), else 0. 29func pr_note(cap: *u8, nishi: i64, incumbent: i64, lower_better: i64, lfd: i64) -> i64 { 30 var behind: i64 = 0 31 if lower_better == 1 { if nishi > incumbent { behind = 1 } } else { if nishi < incumbent { behind = 1 } } 32 let buf: *u8 = sys_mmap(512); var o: i64 = 0 33 o = pr_cat(buf, o, "PERF-REHEARSAL cap=" as *u8); o = pr_cat(buf, o, cap) 34 o = pr_cat(buf, o, " nishi=" as *u8); o = pr_catn(buf, o, nishi) 35 o = pr_cat(buf, o, " incumbent=" as *u8); o = pr_catn(buf, o, incumbent) 36 if behind == 1 { o = pr_cat(buf, o, " verdict=DRILL-CALLED (slow=loses-race -> weakest section -> woodshed/optimize)\n" as *u8) } 37 else { o = pr_cat(buf, o, " verdict=EXCEED-READY (wins the race -> readiness++)\n" as *u8) } 38 sys_write(1, buf, o) 39 if lfd >= 0 { sys_write(lfd, buf, o) } 40 return behind 41} 42 43func main() -> i64 { 44 pr_p("=== NISHI PERF REHEARSAL -- the conductor's weakest-section call, now driven by RACE analytics ===\n" as *u8) 45 pr_p(" (closes the loop: a GREEN-but-SLOW capability that loses races is now seen + drilled, not just gate-reds)\n" as *u8) 46 let lfd: i64 = sys_openat_append(PR_LOG, 0x1a4) 47 48 // --- REAL analytics in: nx_apm_sweep MEASURED the live site this session; the room number is the measured exceed --- 49 pr_p("[external race] deliver a website -- TLS handshake under concurrency, MEASURED by nx_apm_sweep just now:\n" as *u8) 50 let b1: i64 = pr_note("web.tls_handshake_ms" as *u8, PR_MAGIC_1105, 100, 1, lfd) // REAL: apm_sweep certloop ~1050ms -> tls ~1105ms vs ~100ms incumbent -> BEHIND 51 pr_p("[internal race] room loss-resilience -- frozen frames @250ms RTT, MEASURED (nx_room_resilience):\n" as *u8) 52 let b2: i64 = pr_note("room.frozen_frames" as *u8, 16, 118, 1, lfd) // REAL measured exceed: 16 vs 118 frozen -> EXCEED 53 54 if lfd >= 0 { sys_close(lfd) } 55 56 // the edge is CLOSED: b1 (slow media) -> the conductor names media.thumb the weakest section + calls its 57 // drill (woodshed/optimize); re-measure after the drill = the s-class-exceed delta on the leaderboard. 58 pr_p("FEEDBACK-EDGE: " as *u8); pr_n(b1); pr_p(" race-loss(es) routed to a sectional drill; " as *u8) 59 pr_n(2 - b1 - b2); pr_p(" win(s) -> readiness. (the conductor now improves the orchestra from PERFORMANCE analytics)\n" as *u8) 60 61 // self-gate: the SLOW one MUST drill (b1=1), the FAST one MUST NOT (b2=0) -- proves the edge classifies on perf 62 if b1 == 1 { if b2 == 0 { 63 pr_p("PERF-REHEARSAL-GATE GREEN -- a green-but-slow capability is caught as the weakest section; a fast one is readiness\n" as *u8) 64 sys_exit(0); return 0 65 } } 66 pr_p("PERF-REHEARSAL-GATE RED\n" as *u8) 67 sys_exit(1); return 1 68}