code wiki / (root) / locality.nx

locality.nx

buildroot/runtime/locality.nx

3553 B105 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

locality.nx -- data-locality markers + cost estimates. EFFICIENCY_ROADMAP ยง1.1. Speed of light = 30 cm/ns. Modern memory / network hierarchy looks like: L1 cache ~1 ns reg-adjacent L2 cache ~5 ns L3 cache ~20 ns DRAM (NUMA-local) ~100 ns DRAM (remote) ~150 ns NVMe SSD ~10,000 ns (10 us) CXL tier-3 mem ~500 ns (emerging) Network LAN ~100,000 ns (100 us) Network WAN ~10,000,000 ns (10 ms) Interplanetary ~minutes+ (light-delay bound) NishiLang today can't reason about ANY of this -- every deref looks equal to the type system. Phase B lifts these constants + markers into the type system so hot loops can be flagged when they cross locality boundaries ('remote deref in hot loop' warning, cost-aware codegen). Phase A: runtime descriptors so library code can attach locality tags to its pointers + query / branch on them. Invariants: LC1 Every LocalityTier constant carries a pessimistic- upper-bound latency in nanoseconds. LC2 Ordering is monotonic: tier N implies latency <= tier N+1. LC3 `locality_worse(a, b)` returns the slower of two tiers -- useful when composing operations.

dependencies 1 imports · 0 importers

syscalls.nx locality.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main locality_worse locality_hot_safe locptr_new locptr_access_cost_ns locality_latency_ns

structs

71struct LocPtr {

consts

35const LOC_REGISTER: i64 = 1
36const LOC_L1: i64 = 2
37const LOC_L2: i64 = 10
38const LOC_L3: i64 = 30
39const LOC_DRAM_LOCAL: i64 = 100
40const LOC_DRAM_REMOTE: i64 = 200
41const LOC_CXL: i64 = 600
42const LOC_NVME: i64 = 15000
43const LOC_NET_LAN: i64 = 200000
44const LOC_NET_WAN: i64 = 50000000
45const LOC_DISTANT: i64 = 1000000000 // moon/mars/satellite

functions

50func locality_latency_ns(tier: i64) -> i64 {
55func locality_worse(a: i64, b: i64) -> i64 {
called by 1: main
61func locality_hot_safe(tier: i64) -> i64 {
called by 1: main
77func locptr_new(p: *u8, tier: i64, bytes: i64) -> *LocPtr {
called by 1: main
87func locptr_access_cost_ns(lp: *LocPtr, n_reads: i64) -> i64 {
called by 1: main calls 1: locality_latency_ns
92func main() -> i64 {