Files
DCCONSTRUCTIONS 69dc566665 feat(research): preserve urban geometry pipelines and qualification suites
Preserve offline geometry, marking, replay and evaluation pipelines with source manifests and synthetic tests. Research qualification does not activate these methods as production navigation.
2026-10-29 09:10:00 +03:00

26 lines
1.3 KiB
Python

"""Byte-bounded observation reuse for one container's ordered admission phase."""
from collections import OrderedDict
import time
class ObservationCache:
def __init__(self,loader,max_bytes):
if type(max_bytes)is not int or max_bytes<=0:raise ValueError('Invalid observation memory budget')
self.loader=loader;self.limit=max_bytes;self.values=OrderedDict();self.bytes=0
self.hits=0;self.misses=0;self.evictions=0;self.peak_bytes=0;self.load_seconds=0.
def __call__(self,key):
if key in self.values:
self.hits+=1;value,size=self.values.pop(key);self.values[key]=(value,size);return value
self.misses+=1;start=time.monotonic();value=self.loader(key);self.load_seconds+=time.monotonic()-start
size=sum(array.nbytes for array in value)
if size<=self.limit:
while self.values and self.bytes+size>self.limit:
_,(_,removed)=self.values.popitem(last=False);self.bytes-=removed;self.evictions+=1
self.values[key]=(value,size);self.bytes+=size;self.peak_bytes=max(self.peak_bytes,self.bytes)
return value
def report(self):
return dict(hits=self.hits,misses=self.misses,evictions=self.evictions,peak_cached_bytes=self.peak_bytes,
maximum_bytes=self.limit,load_seconds=self.load_seconds,lifetime='one admission process; no disk cache')