nx_log_v2.nx
buildroot/runtime/nx_log_v2.nx
about
nx_log_v2.nx -- single-syscall fast emit for real-time competitions.
v1 (nx_log.nx) does ~7 sys_write calls per event (seq + level +
space + tag + space + msg + newline). Each syscall is ~200ns on
modern hardware, so v1 costs ~1.4us per event. In a CASC / SAT-COMP
loop emitting 10k events/sec that's 14ms/sec = 1.4% CPU just on
logging syscalls -- before even counting the format work.
v2 formats the entire line into a single buffer, then issues ONE
sys_write. Expected: ~200ns per event (7x faster). Below-min-level
emit is a single load+compare, ~3ns.
API mirrors v1's nx_log_emit so callers can swap in place. The
NxLogContext struct from v1 is reused -- no schema break.
Performance discipline per cardinal
[[feedback-genealogy-source-lineage-runtime-one-step-ten-sec]]:
EAT the logging cost (don't strip in production), but EAT_LESS_THAN_BEFORE.
dependencies 2 imports · 1 importers
imports: nx_syscalls.nxnx_log.nx
imported by: nx_log_v2_test.nx
structs
| none |
consts
| 29 | const NX_LOG_V2_BUF_BYTES: i64 = 1024 |
functions
| 41 | func nx_log_v2_buf() -> *u8 |
| 51 | func nx_log_v2_slen(s: *u8) -> i64 called by 1: nx_log_v2_emit |
| 58 | func nx_log_v2_memcpy(dst: *u8, src: *u8, n: i64) -> i64 called by 1: nx_log_v2_emit |
| 68 | func nx_log_v2_write_seq(buf: *u8, off: i64, seq: i64) -> i64 called by 1: nx_log_v2_emit |
| 81 | func nx_log_v2_write_level(buf: *u8, off: i64, level: i64) -> i64 called by 1: nx_log_v2_emit |
| 115 | func nx_log_v2_emit(ctx: *NxLogContext, level: i64, |
| 160 | func nx_log_v2_info(tag: *u8, msg: *u8) -> i64 |
| 163 | func nx_log_v2_warn(tag: *u8, msg: *u8) -> i64 |
| 166 | func nx_log_v2_error(tag: *u8, msg: *u8) -> i64 |