nx_metabolism.nx
buildroot/runtime/nx_metabolism.nx
about
nx_metabolism.nx -- per-call-site profiler + tier promotion.
Biological analogue: cells consume more glucose at hot signaling
pathways and grow mitochondria to compensate. Nishi metabolism
tracks (hit_count, total_cycles, ram_peak) per call site and
suggests a target tier for the existing nxc2 codegen layer to
emit: interpreted bytecode -> AOT native -> SIMD-vectorized native
-> GPU offload -> custom-silicon block.
THIS IS THE OPTIMIZATION DECISION LAYER. nxc2 already has thirteen
architecture backends compiled in (aarch64.c, armv7a.c, cortex_m.c,
gcn.c, loongarch64.c, metal.c, mips64.c, ppc64le.c, ptx.c, riscv.c,
riscv32.c, s390x.c, wasm.c, x86_64.c). What was missing is the
NishiLang-side decision primitive that says WHICH backend to pick
per call site. Metabolism is that primitive.
Composes:
nx_tier -- NX_TIER_MCU..NX_TIER_HPC target enum
nx_budget -- ram_peak per site informs ceiling tuning
nx_homeostasis -- repeated hot-site overshoot triggers
tropism migration to higher tier
nx_attention_class -- foreground sites get higher promotion bias
(frame-budget pressure outranks build pressure)
V1 ships a flat hash table keyed on site_id. Adaptive thresholds
per tier; defaults derived from heuristics rather than learned.
Gap list (V1 honest perf verdict):
- no online learning (thresholds are static constants)
- no decay (a one-time spike at startup never ages out)
- no cross-site cost-amortization (each site decides alone)
- no silicon target yet (NX_TIER_SOVEREIGN_CHIP returns same as HPC)
genealogy_id: nishi_cardinal_2026-05-17_pathway_tropism + cardinal-21_resource_awareness
lineage_id: substrate_metabolism_v1
nx_safety_envelope:
intended_use: "Per-call-site profiling and target-tier
promotion suggestions for the codegen layer"
sil_target: SIL1
dependencies 2 imports · 8 importers
imports: nx_syscalls.nxnx_tier.nx
imported by: nx_ecosystem_compose_test.nxnx_homeostasis.nxnx_homeostasis_test.nxnx_metabolism_test.nxnx_pathway_test.nxnx_ribosome.nxnx_ribosome_test.nxnx_substrate_compose_test.nx
structs
| 58 | struct NxCallSite |
| 69 | struct NxMetabolism |
consts
| 49 | const NX_METAB_OK: nx_int = 0 |
| 50 | const NX_METAB_ERR_FULL: nx_int = 1 // site table at capacity |
| 51 | const NX_METAB_ERR_BAD_SITE: nx_int = 2 |
| 75 | const NX_METAB_DEFAULT_CAPACITY: nx_size = 256 |
| 81 | const NX_METAB_PROMOTE_TO_NATIVE_AT: nx_size = 64 |
| 82 | const NX_METAB_PROMOTE_TO_VECTOR_AT: nx_size = 4096 |
| 83 | const NX_METAB_PROMOTE_TO_GPU_AT: nx_size = 65536 |
| 84 | const NX_METAB_PROMOTE_TO_SILICON_AT: nx_size = 1048576 |
functions
| 88 | func nx_metab_new(capacity: nx_size) -> *NxMetabolism |
| 103 | func _metab_lookup(m: *NxMetabolism, site_id: nx_int) -> *NxCallSite |
| 119 | func nx_metab_record(m: *NxMetabolism, |
| 150 | func nx_metab_suggest_target(m: *NxMetabolism, site_id: nx_int) -> nx_int |
| 163 | func nx_metab_avg_cycles(m: *NxMetabolism, site_id: nx_int) -> nx_size |
| 172 | func nx_metab_hit_count(m: *NxMetabolism, site_id: nx_int) -> nx_size |