locality.nx
buildroot/runtime/locality.nx
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
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 71 | struct LocPtr { |
consts
| 35 | const LOC_REGISTER: i64 = 1 |
| 36 | const LOC_L1: i64 = 2 |
| 37 | const LOC_L2: i64 = 10 |
| 38 | const LOC_L3: i64 = 30 |
| 39 | const LOC_DRAM_LOCAL: i64 = 100 |
| 40 | const LOC_DRAM_REMOTE: i64 = 200 |
| 41 | const LOC_CXL: i64 = 600 |
| 42 | const LOC_NVME: i64 = 15000 |
| 43 | const LOC_NET_LAN: i64 = 200000 |
| 44 | const LOC_NET_WAN: i64 = 50000000 |
| 45 | const LOC_DISTANT: i64 = 1000000000 // moon/mars/satellite |
functions
| 50 | func locality_latency_ns(tier: i64) -> i64 {
called by 1: locptr_access_cost_ns |
| 55 | func locality_worse(a: i64, b: i64) -> i64 {
called by 1: main |
| 61 | func locality_hot_safe(tier: i64) -> i64 {
called by 1: main |
| 77 | func locptr_new(p: *u8, tier: i64, bytes: i64) -> *LocPtr {
called by 1: main |
| 87 | func locptr_access_cost_ns(lp: *LocPtr, n_reads: i64) -> i64 { |
| 92 | func main() -> i64 { |