import json, math, itertools KIND="Constructed analytical model; not a measured benchmark" def fig(i,title,xlabel,ylabel,series,caption,assumptions): return dict(id=i,title=title,x_label=xlabel,y_label=ylabel,series=series,caption=caption,assumptions=assumptions,kind=KIND) def check(name,passed,cases,detail): assert passed, name return dict(name=name,passed=bool(passed),cases=cases,detail=detail) def levels(r,t): n=0; capacity=1 while capacity8*33) for v in vals for u in (0,.2,.8,.98)),40,'Algebraic byte threshold checked against direct accounting.'),check('Positive garbage-collection cost increases with live fraction',all(separated(v,.8)>separated(v,.2) for v in vals),10,'The collector rewrites a stationary live fraction.')] debt=0; history=[] for rate in [3]*10+[1]*30: debt=max(0,debt+rate*33-40);history.append(debt) return dict(slug='lsm-compaction-budgets',checks=tests,figures=[fig('amplification','Explicit rewrite-budget approximation','Size ratio T','Physical / logical bytes',[dict(name='Leveled budget 1 + T L',x=ratios,y=[1+t*l for t,l in zip(ratios,ls)]),dict(name='Tiered asymptotic budget 1 + L',x=ratios,y=[1+l for l in ls])],'Fixed database-to-buffer ratio 4096; staircase levels. Budgets are illustrative, not RocksDB predictions.',['All records equal size','No compression, WAL, or cache effects','Full capacity levels']),fig('value-separation','Value size and collector occupancy','Value bytes','Physical / logical bytes',[dict(name='Inline budget',x=vals,y=[33]*len(vals)),dict(name='Separated; live fraction 0.2',x=vals,y=[separated(v,.2) for v in vals]),dict(name='Separated; live fraction 0.8',x=vals,y=[separated(v,.8) for v in vals])],'Key 16 bytes, pointer 8 bytes, index rewrite factor 33; steady recycling factor 1/(1-u).',['Collector live fraction fixed independently of key distribution','Initial value append included','No pointer repair writes'])],result_summary=dict(levels_T8=levels(4096,8),inline_factor=33,separated_1024_live_02=separated(1024,.2),separated_1024_live_08=separated(1024,.8),peak_debt_MB=max(history),debt_after_40s_MB=debt,tiered_64_T4_bytes=tier_sim(64,4))) if __name__=="__main__": print(json.dumps(run(),indent=2))