[{"data":1,"prerenderedAt":2852},["ShallowReactive",2],{"article-en-bitwise-page-routing-blite-storage-engine":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"tags":11,"body":19,"_type":2845,"_id":2846,"_source":2847,"_file":2848,"_stem":2849,"_extension":2850,"sitemap":2851},"\u002Fen\u002Fblog\u002Fbitwise-page-routing-blite-storage-engine","blog",false,"","Four Files or One: BLite's Bitwise Page Routing","How BLite encodes the file type, collection slot, and local page number into a single uint — and why this self-describing page ID lets the storage engine route reads and writes across multiple memory-mapped files with a bitmask and no schema lookup.","2026-03-24",[12,13,14,15,16,17,18],".net","blite","storage-engine","memory-mapped-files","bitwise","performance","open-source",{"type":20,"children":21,"toc":2831},"root",[22,30,34,41,55,60,471,504,517,520,526,539,547,552,760,794,947,952,1221,1233,1236,1248,1253,1687,1737,1750,1753,1765,1770,1775,2004,2009,2012,2018,2031,2275,2295,2307,2310,2330,2348,2574,2622,2625,2631,2636,2740,2745,2748,2754,2759,2770,2789,2792,2798,2810,2825],{"type":23,"tag":24,"props":25,"children":26},"element","p",{},[27],{"type":28,"value":29},"text","Most embedded databases use a single file. Simple, reliable, easy to reason about. But BLite supports four deployment modes — from a single unified file to per-collection files to a client\u002Fserver split — and the code that handles them is surprisingly small. The trick is encoding routing information directly into the page ID.",{"type":23,"tag":31,"props":32,"children":33},"hr",{},[],{"type":23,"tag":35,"props":36,"children":38},"h2",{"id":37},"the-deployment-problem",[39],{"type":28,"value":40},"The Deployment Problem",{"type":23,"tag":24,"props":42,"children":43},{},[44,46,53],{"type":28,"value":45},"An embedded database has competing requirements. A small CLI tool wants a single ",{"type":23,"tag":47,"props":48,"children":50},"code",{"className":49},[],[51],{"type":28,"value":52},".db",{"type":28,"value":54}," file it can copy and delete. A multi-tenant application wants collections to live in separate files so they can be independently backed up or migrated. A server process wants the index in its own file, separate from the data, for different I\u002FO access patterns.",{"type":23,"tag":24,"props":56,"children":57},{},[58],{"type":28,"value":59},"BLite solves this with four named configurations:",{"type":23,"tag":61,"props":62,"children":66},"pre",{"code":63,"language":64,"meta":7,"className":65,"style":7},"public static class PageFileConfig\n{\n    public static Config Embedded(string databasePath) =>\n        new(Mode.Embedded, databasePath, null);\n\n    public static Config SeparateIndex(string databasePath) =>\n        new(Mode.SeparateIndex, databasePath, null);\n\n    public static Config PerCollection(string databasePath) =>\n        new(Mode.PerCollection, databasePath, null);\n\n    public static Config Server(string databasePath) =>\n        new(Mode.Server, databasePath, null);\n}\n","csharp","language-csharp shiki shiki-themes one-dark-pro",[67],{"type":23,"tag":47,"props":68,"children":69},{"__ignoreMap":7},[70,98,108,152,202,212,249,290,298,335,376,384,421,462],{"type":23,"tag":71,"props":72,"children":75},"span",{"class":73,"line":74},"line",1,[76,82,87,92],{"type":23,"tag":71,"props":77,"children":79},{"style":78},"--shiki-default:#C678DD",[80],{"type":28,"value":81},"public",{"type":23,"tag":71,"props":83,"children":84},{"style":78},[85],{"type":28,"value":86}," static",{"type":23,"tag":71,"props":88,"children":89},{"style":78},[90],{"type":28,"value":91}," class",{"type":23,"tag":71,"props":93,"children":95},{"style":94},"--shiki-default:#E5C07B",[96],{"type":28,"value":97}," PageFileConfig\n",{"type":23,"tag":71,"props":99,"children":101},{"class":73,"line":100},2,[102],{"type":23,"tag":71,"props":103,"children":105},{"style":104},"--shiki-default:#ABB2BF",[106],{"type":28,"value":107},"{\n",{"type":23,"tag":71,"props":109,"children":111},{"class":73,"line":110},3,[112,117,121,126,132,137,142,147],{"type":23,"tag":71,"props":113,"children":114},{"style":78},[115],{"type":28,"value":116},"    public",{"type":23,"tag":71,"props":118,"children":119},{"style":78},[120],{"type":28,"value":86},{"type":23,"tag":71,"props":122,"children":123},{"style":94},[124],{"type":28,"value":125}," Config",{"type":23,"tag":71,"props":127,"children":129},{"style":128},"--shiki-default:#61AFEF",[130],{"type":28,"value":131}," Embedded",{"type":23,"tag":71,"props":133,"children":134},{"style":104},[135],{"type":28,"value":136},"(",{"type":23,"tag":71,"props":138,"children":139},{"style":78},[140],{"type":28,"value":141},"string",{"type":23,"tag":71,"props":143,"children":144},{"style":94},[145],{"type":28,"value":146}," databasePath",{"type":23,"tag":71,"props":148,"children":149},{"style":104},[150],{"type":28,"value":151},") =>\n",{"type":23,"tag":71,"props":153,"children":155},{"class":73,"line":154},4,[156,161,166,171,176,181,187,191,197],{"type":23,"tag":71,"props":157,"children":158},{"style":104},[159],{"type":28,"value":160},"        new(",{"type":23,"tag":71,"props":162,"children":163},{"style":94},[164],{"type":28,"value":165},"Mode",{"type":23,"tag":71,"props":167,"children":168},{"style":104},[169],{"type":28,"value":170},".",{"type":23,"tag":71,"props":172,"children":173},{"style":94},[174],{"type":28,"value":175},"Embedded",{"type":23,"tag":71,"props":177,"children":178},{"style":104},[179],{"type":28,"value":180},", ",{"type":23,"tag":71,"props":182,"children":184},{"style":183},"--shiki-default:#E06C75",[185],{"type":28,"value":186},"databasePath",{"type":23,"tag":71,"props":188,"children":189},{"style":104},[190],{"type":28,"value":180},{"type":23,"tag":71,"props":192,"children":194},{"style":193},"--shiki-default:#D19A66",[195],{"type":28,"value":196},"null",{"type":23,"tag":71,"props":198,"children":199},{"style":104},[200],{"type":28,"value":201},");\n",{"type":23,"tag":71,"props":203,"children":205},{"class":73,"line":204},5,[206],{"type":23,"tag":71,"props":207,"children":209},{"emptyLinePlaceholder":208},true,[210],{"type":28,"value":211},"\n",{"type":23,"tag":71,"props":213,"children":215},{"class":73,"line":214},6,[216,220,224,228,233,237,241,245],{"type":23,"tag":71,"props":217,"children":218},{"style":78},[219],{"type":28,"value":116},{"type":23,"tag":71,"props":221,"children":222},{"style":78},[223],{"type":28,"value":86},{"type":23,"tag":71,"props":225,"children":226},{"style":94},[227],{"type":28,"value":125},{"type":23,"tag":71,"props":229,"children":230},{"style":128},[231],{"type":28,"value":232}," SeparateIndex",{"type":23,"tag":71,"props":234,"children":235},{"style":104},[236],{"type":28,"value":136},{"type":23,"tag":71,"props":238,"children":239},{"style":78},[240],{"type":28,"value":141},{"type":23,"tag":71,"props":242,"children":243},{"style":94},[244],{"type":28,"value":146},{"type":23,"tag":71,"props":246,"children":247},{"style":104},[248],{"type":28,"value":151},{"type":23,"tag":71,"props":250,"children":252},{"class":73,"line":251},7,[253,257,261,265,270,274,278,282,286],{"type":23,"tag":71,"props":254,"children":255},{"style":104},[256],{"type":28,"value":160},{"type":23,"tag":71,"props":258,"children":259},{"style":94},[260],{"type":28,"value":165},{"type":23,"tag":71,"props":262,"children":263},{"style":104},[264],{"type":28,"value":170},{"type":23,"tag":71,"props":266,"children":267},{"style":94},[268],{"type":28,"value":269},"SeparateIndex",{"type":23,"tag":71,"props":271,"children":272},{"style":104},[273],{"type":28,"value":180},{"type":23,"tag":71,"props":275,"children":276},{"style":183},[277],{"type":28,"value":186},{"type":23,"tag":71,"props":279,"children":280},{"style":104},[281],{"type":28,"value":180},{"type":23,"tag":71,"props":283,"children":284},{"style":193},[285],{"type":28,"value":196},{"type":23,"tag":71,"props":287,"children":288},{"style":104},[289],{"type":28,"value":201},{"type":23,"tag":71,"props":291,"children":293},{"class":73,"line":292},8,[294],{"type":23,"tag":71,"props":295,"children":296},{"emptyLinePlaceholder":208},[297],{"type":28,"value":211},{"type":23,"tag":71,"props":299,"children":301},{"class":73,"line":300},9,[302,306,310,314,319,323,327,331],{"type":23,"tag":71,"props":303,"children":304},{"style":78},[305],{"type":28,"value":116},{"type":23,"tag":71,"props":307,"children":308},{"style":78},[309],{"type":28,"value":86},{"type":23,"tag":71,"props":311,"children":312},{"style":94},[313],{"type":28,"value":125},{"type":23,"tag":71,"props":315,"children":316},{"style":128},[317],{"type":28,"value":318}," PerCollection",{"type":23,"tag":71,"props":320,"children":321},{"style":104},[322],{"type":28,"value":136},{"type":23,"tag":71,"props":324,"children":325},{"style":78},[326],{"type":28,"value":141},{"type":23,"tag":71,"props":328,"children":329},{"style":94},[330],{"type":28,"value":146},{"type":23,"tag":71,"props":332,"children":333},{"style":104},[334],{"type":28,"value":151},{"type":23,"tag":71,"props":336,"children":338},{"class":73,"line":337},10,[339,343,347,351,356,360,364,368,372],{"type":23,"tag":71,"props":340,"children":341},{"style":104},[342],{"type":28,"value":160},{"type":23,"tag":71,"props":344,"children":345},{"style":94},[346],{"type":28,"value":165},{"type":23,"tag":71,"props":348,"children":349},{"style":104},[350],{"type":28,"value":170},{"type":23,"tag":71,"props":352,"children":353},{"style":94},[354],{"type":28,"value":355},"PerCollection",{"type":23,"tag":71,"props":357,"children":358},{"style":104},[359],{"type":28,"value":180},{"type":23,"tag":71,"props":361,"children":362},{"style":183},[363],{"type":28,"value":186},{"type":23,"tag":71,"props":365,"children":366},{"style":104},[367],{"type":28,"value":180},{"type":23,"tag":71,"props":369,"children":370},{"style":193},[371],{"type":28,"value":196},{"type":23,"tag":71,"props":373,"children":374},{"style":104},[375],{"type":28,"value":201},{"type":23,"tag":71,"props":377,"children":379},{"class":73,"line":378},11,[380],{"type":23,"tag":71,"props":381,"children":382},{"emptyLinePlaceholder":208},[383],{"type":28,"value":211},{"type":23,"tag":71,"props":385,"children":387},{"class":73,"line":386},12,[388,392,396,400,405,409,413,417],{"type":23,"tag":71,"props":389,"children":390},{"style":78},[391],{"type":28,"value":116},{"type":23,"tag":71,"props":393,"children":394},{"style":78},[395],{"type":28,"value":86},{"type":23,"tag":71,"props":397,"children":398},{"style":94},[399],{"type":28,"value":125},{"type":23,"tag":71,"props":401,"children":402},{"style":128},[403],{"type":28,"value":404}," Server",{"type":23,"tag":71,"props":406,"children":407},{"style":104},[408],{"type":28,"value":136},{"type":23,"tag":71,"props":410,"children":411},{"style":78},[412],{"type":28,"value":141},{"type":23,"tag":71,"props":414,"children":415},{"style":94},[416],{"type":28,"value":146},{"type":23,"tag":71,"props":418,"children":419},{"style":104},[420],{"type":28,"value":151},{"type":23,"tag":71,"props":422,"children":424},{"class":73,"line":423},13,[425,429,433,437,442,446,450,454,458],{"type":23,"tag":71,"props":426,"children":427},{"style":104},[428],{"type":28,"value":160},{"type":23,"tag":71,"props":430,"children":431},{"style":94},[432],{"type":28,"value":165},{"type":23,"tag":71,"props":434,"children":435},{"style":104},[436],{"type":28,"value":170},{"type":23,"tag":71,"props":438,"children":439},{"style":94},[440],{"type":28,"value":441},"Server",{"type":23,"tag":71,"props":443,"children":444},{"style":104},[445],{"type":28,"value":180},{"type":23,"tag":71,"props":447,"children":448},{"style":183},[449],{"type":28,"value":186},{"type":23,"tag":71,"props":451,"children":452},{"style":104},[453],{"type":28,"value":180},{"type":23,"tag":71,"props":455,"children":456},{"style":193},[457],{"type":28,"value":196},{"type":23,"tag":71,"props":459,"children":460},{"style":104},[461],{"type":28,"value":201},{"type":23,"tag":71,"props":463,"children":465},{"class":73,"line":464},14,[466],{"type":23,"tag":71,"props":467,"children":468},{"style":104},[469],{"type":28,"value":470},"}\n",{"type":23,"tag":24,"props":472,"children":473},{},[474,476,481,483,488,490,495,497,502],{"type":28,"value":475},"In ",{"type":23,"tag":47,"props":477,"children":479},{"className":478},[],[480],{"type":28,"value":175},{"type":28,"value":482}," mode, everything — data, indexes, metadata — lives in one file. In ",{"type":23,"tag":47,"props":484,"children":486},{"className":485},[],[487],{"type":28,"value":269},{"type":28,"value":489},", the index gets its own file. In ",{"type":23,"tag":47,"props":491,"children":493},{"className":492},[],[494],{"type":28,"value":355},{"type":28,"value":496},", each collection gets its own file. In ",{"type":23,"tag":47,"props":498,"children":500},{"className":499},[],[501],{"type":28,"value":441},{"type":28,"value":503},", the storage engine acts as a remote file store managed by a server process.",{"type":23,"tag":24,"props":505,"children":506},{},[507,509,515],{"type":28,"value":508},"The challenge: code that writes or reads a page shouldn't need to know which mode it's in. It should just call ",{"type":23,"tag":47,"props":510,"children":512},{"className":511},[],[513],{"type":28,"value":514},"ReadPage(pageId)",{"type":28,"value":516}," and get the right bytes, regardless of how many files the data is split across.",{"type":23,"tag":31,"props":518,"children":519},{},[],{"type":23,"tag":35,"props":521,"children":523},{"id":522},"the-self-describing-page-id",[524],{"type":28,"value":525},"The Self-Describing Page ID",{"type":23,"tag":24,"props":527,"children":528},{},[529,531,537],{"type":28,"value":530},"BLite encodes the file type, collection slot, and local page number into a single ",{"type":23,"tag":47,"props":532,"children":534},{"className":533},[],[535],{"type":28,"value":536},"uint",{"type":28,"value":538},":",{"type":23,"tag":61,"props":540,"children":542},{"code":541},"Bit 31: index page marker     (1 = index file)\nBit 30: collection page marker (1 when combined with bit 31 = 11)\nBits 29-24: collection slot   (6 bits → up to 64 collections)\nBits 23-0:  local page number  (24 bits → up to 16,777,215 pages per file)\n",[543],{"type":23,"tag":47,"props":544,"children":545},{"__ignoreMap":7},[546],{"type":28,"value":541},{"type":23,"tag":24,"props":548,"children":549},{},[550],{"type":28,"value":551},"The two high bits define the file type:",{"type":23,"tag":61,"props":553,"children":555},{"code":554,"language":64,"meta":7,"className":65,"style":7},"private const uint IndexPageMarker      = 0x8000_0000u; \u002F\u002F bit 31: 10xx xxxx ...\nprivate const uint CollectionPageMarker = 0xC000_0000u; \u002F\u002F bits 31-30: 11xx xxxx ...\nprivate const uint CollectionSlotMask   = 0x3F00_0000u; \u002F\u002F bits 29-24\nprivate const uint LocalPageMask        = 0x00FF_FFFFu; \u002F\u002F bits 23-0\nprivate const uint IndexLocalMask       = 0x7FFF_FFFFu; \u002F\u002F bits 30-0 (for index files)\n",[556],{"type":23,"tag":47,"props":557,"children":558},{"__ignoreMap":7},[559,604,643,682,721],{"type":23,"tag":71,"props":560,"children":561},{"class":73,"line":74},[562,567,572,577,582,588,593,598],{"type":23,"tag":71,"props":563,"children":564},{"style":78},[565],{"type":28,"value":566},"private",{"type":23,"tag":71,"props":568,"children":569},{"style":78},[570],{"type":28,"value":571}," const",{"type":23,"tag":71,"props":573,"children":574},{"style":78},[575],{"type":28,"value":576}," uint",{"type":23,"tag":71,"props":578,"children":579},{"style":183},[580],{"type":28,"value":581}," IndexPageMarker",{"type":23,"tag":71,"props":583,"children":585},{"style":584},"--shiki-default:#56B6C2",[586],{"type":28,"value":587},"      =",{"type":23,"tag":71,"props":589,"children":590},{"style":193},[591],{"type":28,"value":592}," 0x8000_0000u",{"type":23,"tag":71,"props":594,"children":595},{"style":104},[596],{"type":28,"value":597},"; ",{"type":23,"tag":71,"props":599,"children":601},{"style":600},"--shiki-default:#7F848E;--shiki-default-font-style:italic",[602],{"type":28,"value":603},"\u002F\u002F bit 31: 10xx xxxx ...\n",{"type":23,"tag":71,"props":605,"children":606},{"class":73,"line":100},[607,611,615,619,624,629,634,638],{"type":23,"tag":71,"props":608,"children":609},{"style":78},[610],{"type":28,"value":566},{"type":23,"tag":71,"props":612,"children":613},{"style":78},[614],{"type":28,"value":571},{"type":23,"tag":71,"props":616,"children":617},{"style":78},[618],{"type":28,"value":576},{"type":23,"tag":71,"props":620,"children":621},{"style":183},[622],{"type":28,"value":623}," CollectionPageMarker",{"type":23,"tag":71,"props":625,"children":626},{"style":584},[627],{"type":28,"value":628}," =",{"type":23,"tag":71,"props":630,"children":631},{"style":193},[632],{"type":28,"value":633}," 0xC000_0000u",{"type":23,"tag":71,"props":635,"children":636},{"style":104},[637],{"type":28,"value":597},{"type":23,"tag":71,"props":639,"children":640},{"style":600},[641],{"type":28,"value":642},"\u002F\u002F bits 31-30: 11xx xxxx ...\n",{"type":23,"tag":71,"props":644,"children":645},{"class":73,"line":110},[646,650,654,658,663,668,673,677],{"type":23,"tag":71,"props":647,"children":648},{"style":78},[649],{"type":28,"value":566},{"type":23,"tag":71,"props":651,"children":652},{"style":78},[653],{"type":28,"value":571},{"type":23,"tag":71,"props":655,"children":656},{"style":78},[657],{"type":28,"value":576},{"type":23,"tag":71,"props":659,"children":660},{"style":183},[661],{"type":28,"value":662}," CollectionSlotMask",{"type":23,"tag":71,"props":664,"children":665},{"style":584},[666],{"type":28,"value":667},"   =",{"type":23,"tag":71,"props":669,"children":670},{"style":193},[671],{"type":28,"value":672}," 0x3F00_0000u",{"type":23,"tag":71,"props":674,"children":675},{"style":104},[676],{"type":28,"value":597},{"type":23,"tag":71,"props":678,"children":679},{"style":600},[680],{"type":28,"value":681},"\u002F\u002F bits 29-24\n",{"type":23,"tag":71,"props":683,"children":684},{"class":73,"line":154},[685,689,693,697,702,707,712,716],{"type":23,"tag":71,"props":686,"children":687},{"style":78},[688],{"type":28,"value":566},{"type":23,"tag":71,"props":690,"children":691},{"style":78},[692],{"type":28,"value":571},{"type":23,"tag":71,"props":694,"children":695},{"style":78},[696],{"type":28,"value":576},{"type":23,"tag":71,"props":698,"children":699},{"style":183},[700],{"type":28,"value":701}," LocalPageMask",{"type":23,"tag":71,"props":703,"children":704},{"style":584},[705],{"type":28,"value":706},"        =",{"type":23,"tag":71,"props":708,"children":709},{"style":193},[710],{"type":28,"value":711}," 0x00FF_FFFFu",{"type":23,"tag":71,"props":713,"children":714},{"style":104},[715],{"type":28,"value":597},{"type":23,"tag":71,"props":717,"children":718},{"style":600},[719],{"type":28,"value":720},"\u002F\u002F bits 23-0\n",{"type":23,"tag":71,"props":722,"children":723},{"class":73,"line":204},[724,728,732,736,741,746,751,755],{"type":23,"tag":71,"props":725,"children":726},{"style":78},[727],{"type":28,"value":566},{"type":23,"tag":71,"props":729,"children":730},{"style":78},[731],{"type":28,"value":571},{"type":23,"tag":71,"props":733,"children":734},{"style":78},[735],{"type":28,"value":576},{"type":23,"tag":71,"props":737,"children":738},{"style":183},[739],{"type":28,"value":740}," IndexLocalMask",{"type":23,"tag":71,"props":742,"children":743},{"style":584},[744],{"type":28,"value":745},"       =",{"type":23,"tag":71,"props":747,"children":748},{"style":193},[749],{"type":28,"value":750}," 0x7FFF_FFFFu",{"type":23,"tag":71,"props":752,"children":753},{"style":104},[754],{"type":28,"value":597},{"type":23,"tag":71,"props":756,"children":757},{"style":600},[758],{"type":28,"value":759},"\u002F\u002F bits 30-0 (for index files)\n",{"type":23,"tag":24,"props":761,"children":762},{},[763,765,770,772,778,779,785,786,792],{"type":28,"value":764},"When ",{"type":23,"tag":47,"props":766,"children":768},{"className":767},[],[769],{"type":28,"value":175},{"type":28,"value":771}," mode uses just the main file, page IDs look like plain sequential integers: ",{"type":23,"tag":47,"props":773,"children":775},{"className":774},[],[776],{"type":28,"value":777},"1",{"type":28,"value":180},{"type":23,"tag":47,"props":780,"children":782},{"className":781},[],[783],{"type":28,"value":784},"2",{"type":28,"value":180},{"type":23,"tag":47,"props":787,"children":789},{"className":788},[],[790],{"type":28,"value":791},"3",{"type":28,"value":793},", …. No bits are set in the top positions. When the storage engine allocates an index page, it OR-in the marker:",{"type":23,"tag":61,"props":795,"children":797},{"code":796,"language":64,"meta":7,"className":65,"style":7},"public uint AllocateIndexPage(ITransaction? transaction = null)\n{\n    uint localId = _indexFile.AllocatePage(transaction);\n    return IndexPageMarker | (localId & IndexLocalMask);\n}\n",[798],{"type":23,"tag":47,"props":799,"children":800},{"__ignoreMap":7},[801,850,857,900,940],{"type":23,"tag":71,"props":802,"children":803},{"class":73,"line":74},[804,808,812,817,821,826,831,836,840,845],{"type":23,"tag":71,"props":805,"children":806},{"style":78},[807],{"type":28,"value":81},{"type":23,"tag":71,"props":809,"children":810},{"style":78},[811],{"type":28,"value":576},{"type":23,"tag":71,"props":813,"children":814},{"style":128},[815],{"type":28,"value":816}," AllocateIndexPage",{"type":23,"tag":71,"props":818,"children":819},{"style":104},[820],{"type":28,"value":136},{"type":23,"tag":71,"props":822,"children":823},{"style":94},[824],{"type":28,"value":825},"ITransaction",{"type":23,"tag":71,"props":827,"children":828},{"style":104},[829],{"type":28,"value":830},"? ",{"type":23,"tag":71,"props":832,"children":833},{"style":94},[834],{"type":28,"value":835},"transaction",{"type":23,"tag":71,"props":837,"children":838},{"style":584},[839],{"type":28,"value":628},{"type":23,"tag":71,"props":841,"children":842},{"style":193},[843],{"type":28,"value":844}," null",{"type":23,"tag":71,"props":846,"children":847},{"style":104},[848],{"type":28,"value":849},")\n",{"type":23,"tag":71,"props":851,"children":852},{"class":73,"line":100},[853],{"type":23,"tag":71,"props":854,"children":855},{"style":104},[856],{"type":28,"value":107},{"type":23,"tag":71,"props":858,"children":859},{"class":73,"line":110},[860,865,870,874,879,883,888,892,896],{"type":23,"tag":71,"props":861,"children":862},{"style":78},[863],{"type":28,"value":864},"    uint",{"type":23,"tag":71,"props":866,"children":867},{"style":183},[868],{"type":28,"value":869}," localId",{"type":23,"tag":71,"props":871,"children":872},{"style":584},[873],{"type":28,"value":628},{"type":23,"tag":71,"props":875,"children":876},{"style":94},[877],{"type":28,"value":878}," _indexFile",{"type":23,"tag":71,"props":880,"children":881},{"style":104},[882],{"type":28,"value":170},{"type":23,"tag":71,"props":884,"children":885},{"style":128},[886],{"type":28,"value":887},"AllocatePage",{"type":23,"tag":71,"props":889,"children":890},{"style":104},[891],{"type":28,"value":136},{"type":23,"tag":71,"props":893,"children":894},{"style":183},[895],{"type":28,"value":835},{"type":23,"tag":71,"props":897,"children":898},{"style":104},[899],{"type":28,"value":201},{"type":23,"tag":71,"props":901,"children":902},{"class":73,"line":154},[903,908,912,917,922,927,932,936],{"type":23,"tag":71,"props":904,"children":905},{"style":78},[906],{"type":28,"value":907},"    return",{"type":23,"tag":71,"props":909,"children":910},{"style":183},[911],{"type":28,"value":581},{"type":23,"tag":71,"props":913,"children":914},{"style":584},[915],{"type":28,"value":916}," |",{"type":23,"tag":71,"props":918,"children":919},{"style":104},[920],{"type":28,"value":921}," (",{"type":23,"tag":71,"props":923,"children":924},{"style":183},[925],{"type":28,"value":926},"localId",{"type":23,"tag":71,"props":928,"children":929},{"style":584},[930],{"type":28,"value":931}," &",{"type":23,"tag":71,"props":933,"children":934},{"style":183},[935],{"type":28,"value":740},{"type":23,"tag":71,"props":937,"children":938},{"style":104},[939],{"type":28,"value":201},{"type":23,"tag":71,"props":941,"children":942},{"class":73,"line":204},[943],{"type":23,"tag":71,"props":944,"children":945},{"style":104},[946],{"type":28,"value":470},{"type":23,"tag":24,"props":948,"children":949},{},[950],{"type":28,"value":951},"When it allocates a collection page, it also encodes the 6-bit slot:",{"type":23,"tag":61,"props":953,"children":955},{"code":954,"language":64,"meta":7,"className":65,"style":7},"public uint AllocateCollectionPage(string collectionName, ITransaction? transaction = null)\n{\n    int slot = GetOrAssignCollectionSlot(collectionName);\n    uint localId = _collectionFiles[slot].AllocatePage(transaction);\n    uint slotBits = (uint)(slot & 0x3F) \u003C\u003C 24;\n    return CollectionPageMarker | slotBits | (localId & LocalPageMask);\n}\n",[956],{"type":23,"tag":47,"props":957,"children":958},{"__ignoreMap":7},[959,1016,1023,1058,1109,1171,1214],{"type":23,"tag":71,"props":960,"children":961},{"class":73,"line":74},[962,966,970,975,979,983,988,992,996,1000,1004,1008,1012],{"type":23,"tag":71,"props":963,"children":964},{"style":78},[965],{"type":28,"value":81},{"type":23,"tag":71,"props":967,"children":968},{"style":78},[969],{"type":28,"value":576},{"type":23,"tag":71,"props":971,"children":972},{"style":128},[973],{"type":28,"value":974}," AllocateCollectionPage",{"type":23,"tag":71,"props":976,"children":977},{"style":104},[978],{"type":28,"value":136},{"type":23,"tag":71,"props":980,"children":981},{"style":78},[982],{"type":28,"value":141},{"type":23,"tag":71,"props":984,"children":985},{"style":94},[986],{"type":28,"value":987}," collectionName",{"type":23,"tag":71,"props":989,"children":990},{"style":104},[991],{"type":28,"value":180},{"type":23,"tag":71,"props":993,"children":994},{"style":94},[995],{"type":28,"value":825},{"type":23,"tag":71,"props":997,"children":998},{"style":104},[999],{"type":28,"value":830},{"type":23,"tag":71,"props":1001,"children":1002},{"style":94},[1003],{"type":28,"value":835},{"type":23,"tag":71,"props":1005,"children":1006},{"style":584},[1007],{"type":28,"value":628},{"type":23,"tag":71,"props":1009,"children":1010},{"style":193},[1011],{"type":28,"value":844},{"type":23,"tag":71,"props":1013,"children":1014},{"style":104},[1015],{"type":28,"value":849},{"type":23,"tag":71,"props":1017,"children":1018},{"class":73,"line":100},[1019],{"type":23,"tag":71,"props":1020,"children":1021},{"style":104},[1022],{"type":28,"value":107},{"type":23,"tag":71,"props":1024,"children":1025},{"class":73,"line":110},[1026,1031,1036,1040,1045,1049,1054],{"type":23,"tag":71,"props":1027,"children":1028},{"style":78},[1029],{"type":28,"value":1030},"    int",{"type":23,"tag":71,"props":1032,"children":1033},{"style":183},[1034],{"type":28,"value":1035}," slot",{"type":23,"tag":71,"props":1037,"children":1038},{"style":584},[1039],{"type":28,"value":628},{"type":23,"tag":71,"props":1041,"children":1042},{"style":128},[1043],{"type":28,"value":1044}," GetOrAssignCollectionSlot",{"type":23,"tag":71,"props":1046,"children":1047},{"style":104},[1048],{"type":28,"value":136},{"type":23,"tag":71,"props":1050,"children":1051},{"style":183},[1052],{"type":28,"value":1053},"collectionName",{"type":23,"tag":71,"props":1055,"children":1056},{"style":104},[1057],{"type":28,"value":201},{"type":23,"tag":71,"props":1059,"children":1060},{"class":73,"line":154},[1061,1065,1069,1073,1078,1083,1088,1093,1097,1101,1105],{"type":23,"tag":71,"props":1062,"children":1063},{"style":78},[1064],{"type":28,"value":864},{"type":23,"tag":71,"props":1066,"children":1067},{"style":183},[1068],{"type":28,"value":869},{"type":23,"tag":71,"props":1070,"children":1071},{"style":584},[1072],{"type":28,"value":628},{"type":23,"tag":71,"props":1074,"children":1075},{"style":94},[1076],{"type":28,"value":1077}," _collectionFiles",{"type":23,"tag":71,"props":1079,"children":1080},{"style":104},[1081],{"type":28,"value":1082},"[",{"type":23,"tag":71,"props":1084,"children":1085},{"style":183},[1086],{"type":28,"value":1087},"slot",{"type":23,"tag":71,"props":1089,"children":1090},{"style":104},[1091],{"type":28,"value":1092},"].",{"type":23,"tag":71,"props":1094,"children":1095},{"style":128},[1096],{"type":28,"value":887},{"type":23,"tag":71,"props":1098,"children":1099},{"style":104},[1100],{"type":28,"value":136},{"type":23,"tag":71,"props":1102,"children":1103},{"style":183},[1104],{"type":28,"value":835},{"type":23,"tag":71,"props":1106,"children":1107},{"style":104},[1108],{"type":28,"value":201},{"type":23,"tag":71,"props":1110,"children":1111},{"class":73,"line":204},[1112,1116,1121,1125,1129,1133,1138,1142,1146,1151,1156,1161,1166],{"type":23,"tag":71,"props":1113,"children":1114},{"style":78},[1115],{"type":28,"value":864},{"type":23,"tag":71,"props":1117,"children":1118},{"style":183},[1119],{"type":28,"value":1120}," slotBits",{"type":23,"tag":71,"props":1122,"children":1123},{"style":584},[1124],{"type":28,"value":628},{"type":23,"tag":71,"props":1126,"children":1127},{"style":104},[1128],{"type":28,"value":921},{"type":23,"tag":71,"props":1130,"children":1131},{"style":78},[1132],{"type":28,"value":536},{"type":23,"tag":71,"props":1134,"children":1135},{"style":104},[1136],{"type":28,"value":1137},")(",{"type":23,"tag":71,"props":1139,"children":1140},{"style":183},[1141],{"type":28,"value":1087},{"type":23,"tag":71,"props":1143,"children":1144},{"style":584},[1145],{"type":28,"value":931},{"type":23,"tag":71,"props":1147,"children":1148},{"style":193},[1149],{"type":28,"value":1150}," 0x3F",{"type":23,"tag":71,"props":1152,"children":1153},{"style":104},[1154],{"type":28,"value":1155},") ",{"type":23,"tag":71,"props":1157,"children":1158},{"style":584},[1159],{"type":28,"value":1160},"\u003C\u003C",{"type":23,"tag":71,"props":1162,"children":1163},{"style":193},[1164],{"type":28,"value":1165}," 24",{"type":23,"tag":71,"props":1167,"children":1168},{"style":104},[1169],{"type":28,"value":1170},";\n",{"type":23,"tag":71,"props":1172,"children":1173},{"class":73,"line":214},[1174,1178,1182,1186,1190,1194,1198,1202,1206,1210],{"type":23,"tag":71,"props":1175,"children":1176},{"style":78},[1177],{"type":28,"value":907},{"type":23,"tag":71,"props":1179,"children":1180},{"style":183},[1181],{"type":28,"value":623},{"type":23,"tag":71,"props":1183,"children":1184},{"style":584},[1185],{"type":28,"value":916},{"type":23,"tag":71,"props":1187,"children":1188},{"style":183},[1189],{"type":28,"value":1120},{"type":23,"tag":71,"props":1191,"children":1192},{"style":584},[1193],{"type":28,"value":916},{"type":23,"tag":71,"props":1195,"children":1196},{"style":104},[1197],{"type":28,"value":921},{"type":23,"tag":71,"props":1199,"children":1200},{"style":183},[1201],{"type":28,"value":926},{"type":23,"tag":71,"props":1203,"children":1204},{"style":584},[1205],{"type":28,"value":931},{"type":23,"tag":71,"props":1207,"children":1208},{"style":183},[1209],{"type":28,"value":701},{"type":23,"tag":71,"props":1211,"children":1212},{"style":104},[1213],{"type":28,"value":201},{"type":23,"tag":71,"props":1215,"children":1216},{"class":73,"line":251},[1217],{"type":23,"tag":71,"props":1218,"children":1219},{"style":104},[1220],{"type":28,"value":470},{"type":23,"tag":24,"props":1222,"children":1223},{},[1224,1226,1231],{"type":28,"value":1225},"The result: every ",{"type":23,"tag":47,"props":1227,"children":1229},{"className":1228},[],[1230],{"type":28,"value":536},{"type":28,"value":1232}," page ID is self-describing. You can look at a page ID and immediately know which file it belongs to, which collection it's in, and what its local offset is — without any schema lookup or dictionary.",{"type":23,"tag":31,"props":1234,"children":1235},{},[],{"type":23,"tag":35,"props":1237,"children":1239},{"id":1238},"the-router-getpagefile",[1240,1242],{"type":28,"value":1241},"The Router: ",{"type":23,"tag":47,"props":1243,"children":1245},{"className":1244},[],[1246],{"type":28,"value":1247},"GetPageFile",{"type":23,"tag":24,"props":1249,"children":1250},{},[1251],{"type":28,"value":1252},"All reads and writes go through a single routing function:",{"type":23,"tag":61,"props":1254,"children":1256},{"code":1255,"language":64,"meta":7,"className":65,"style":7},"private IPageFile GetPageFile(uint pageId, out uint physicalPageId)\n{\n    if ((pageId & CollectionPageMarker) == CollectionPageMarker)\n    {\n        \u002F\u002F Bits 31-30 = 11 → collection file\n        int slot = (int)((pageId & CollectionSlotMask) >> 24);\n        physicalPageId = pageId & LocalPageMask;\n        return _collectionFiles[slot];\n    }\n    else if ((pageId & IndexPageMarker) == IndexPageMarker)\n    {\n        \u002F\u002F Bit 31 = 1, bit 30 = 0 → index file\n        physicalPageId = pageId & IndexLocalMask;\n        return _indexFile;\n    }\n    else\n    {\n        \u002F\u002F No high bits set → main page file\n        physicalPageId = pageId;\n        return _mainFile;\n    }\n}\n",[1257],{"type":23,"tag":47,"props":1258,"children":1259},{"__ignoreMap":7},[1260,1312,1319,1362,1370,1378,1437,1465,1490,1498,1543,1550,1558,1585,1600,1608,1617,1625,1634,1654,1671,1679],{"type":23,"tag":71,"props":1261,"children":1262},{"class":73,"line":74},[1263,1267,1272,1277,1281,1285,1290,1294,1299,1303,1308],{"type":23,"tag":71,"props":1264,"children":1265},{"style":78},[1266],{"type":28,"value":566},{"type":23,"tag":71,"props":1268,"children":1269},{"style":94},[1270],{"type":28,"value":1271}," IPageFile",{"type":23,"tag":71,"props":1273,"children":1274},{"style":128},[1275],{"type":28,"value":1276}," GetPageFile",{"type":23,"tag":71,"props":1278,"children":1279},{"style":104},[1280],{"type":28,"value":136},{"type":23,"tag":71,"props":1282,"children":1283},{"style":78},[1284],{"type":28,"value":536},{"type":23,"tag":71,"props":1286,"children":1287},{"style":94},[1288],{"type":28,"value":1289}," pageId",{"type":23,"tag":71,"props":1291,"children":1292},{"style":104},[1293],{"type":28,"value":180},{"type":23,"tag":71,"props":1295,"children":1296},{"style":78},[1297],{"type":28,"value":1298},"out",{"type":23,"tag":71,"props":1300,"children":1301},{"style":78},[1302],{"type":28,"value":576},{"type":23,"tag":71,"props":1304,"children":1305},{"style":94},[1306],{"type":28,"value":1307}," physicalPageId",{"type":23,"tag":71,"props":1309,"children":1310},{"style":104},[1311],{"type":28,"value":849},{"type":23,"tag":71,"props":1313,"children":1314},{"class":73,"line":100},[1315],{"type":23,"tag":71,"props":1316,"children":1317},{"style":104},[1318],{"type":28,"value":107},{"type":23,"tag":71,"props":1320,"children":1321},{"class":73,"line":110},[1322,1327,1332,1337,1341,1345,1349,1354,1358],{"type":23,"tag":71,"props":1323,"children":1324},{"style":78},[1325],{"type":28,"value":1326},"    if",{"type":23,"tag":71,"props":1328,"children":1329},{"style":104},[1330],{"type":28,"value":1331}," ((",{"type":23,"tag":71,"props":1333,"children":1334},{"style":183},[1335],{"type":28,"value":1336},"pageId",{"type":23,"tag":71,"props":1338,"children":1339},{"style":584},[1340],{"type":28,"value":931},{"type":23,"tag":71,"props":1342,"children":1343},{"style":183},[1344],{"type":28,"value":623},{"type":23,"tag":71,"props":1346,"children":1347},{"style":104},[1348],{"type":28,"value":1155},{"type":23,"tag":71,"props":1350,"children":1351},{"style":584},[1352],{"type":28,"value":1353},"==",{"type":23,"tag":71,"props":1355,"children":1356},{"style":183},[1357],{"type":28,"value":623},{"type":23,"tag":71,"props":1359,"children":1360},{"style":104},[1361],{"type":28,"value":849},{"type":23,"tag":71,"props":1363,"children":1364},{"class":73,"line":154},[1365],{"type":23,"tag":71,"props":1366,"children":1367},{"style":104},[1368],{"type":28,"value":1369},"    {\n",{"type":23,"tag":71,"props":1371,"children":1372},{"class":73,"line":204},[1373],{"type":23,"tag":71,"props":1374,"children":1375},{"style":600},[1376],{"type":28,"value":1377},"        \u002F\u002F Bits 31-30 = 11 → collection file\n",{"type":23,"tag":71,"props":1379,"children":1380},{"class":73,"line":214},[1381,1386,1390,1394,1398,1403,1408,1412,1416,1420,1424,1429,1433],{"type":23,"tag":71,"props":1382,"children":1383},{"style":78},[1384],{"type":28,"value":1385},"        int",{"type":23,"tag":71,"props":1387,"children":1388},{"style":183},[1389],{"type":28,"value":1035},{"type":23,"tag":71,"props":1391,"children":1392},{"style":584},[1393],{"type":28,"value":628},{"type":23,"tag":71,"props":1395,"children":1396},{"style":104},[1397],{"type":28,"value":921},{"type":23,"tag":71,"props":1399,"children":1400},{"style":78},[1401],{"type":28,"value":1402},"int",{"type":23,"tag":71,"props":1404,"children":1405},{"style":104},[1406],{"type":28,"value":1407},")((",{"type":23,"tag":71,"props":1409,"children":1410},{"style":183},[1411],{"type":28,"value":1336},{"type":23,"tag":71,"props":1413,"children":1414},{"style":584},[1415],{"type":28,"value":931},{"type":23,"tag":71,"props":1417,"children":1418},{"style":183},[1419],{"type":28,"value":662},{"type":23,"tag":71,"props":1421,"children":1422},{"style":104},[1423],{"type":28,"value":1155},{"type":23,"tag":71,"props":1425,"children":1426},{"style":584},[1427],{"type":28,"value":1428},">>",{"type":23,"tag":71,"props":1430,"children":1431},{"style":193},[1432],{"type":28,"value":1165},{"type":23,"tag":71,"props":1434,"children":1435},{"style":104},[1436],{"type":28,"value":201},{"type":23,"tag":71,"props":1438,"children":1439},{"class":73,"line":251},[1440,1445,1449,1453,1457,1461],{"type":23,"tag":71,"props":1441,"children":1442},{"style":183},[1443],{"type":28,"value":1444},"        physicalPageId",{"type":23,"tag":71,"props":1446,"children":1447},{"style":584},[1448],{"type":28,"value":628},{"type":23,"tag":71,"props":1450,"children":1451},{"style":183},[1452],{"type":28,"value":1289},{"type":23,"tag":71,"props":1454,"children":1455},{"style":584},[1456],{"type":28,"value":931},{"type":23,"tag":71,"props":1458,"children":1459},{"style":183},[1460],{"type":28,"value":701},{"type":23,"tag":71,"props":1462,"children":1463},{"style":104},[1464],{"type":28,"value":1170},{"type":23,"tag":71,"props":1466,"children":1467},{"class":73,"line":292},[1468,1473,1477,1481,1485],{"type":23,"tag":71,"props":1469,"children":1470},{"style":78},[1471],{"type":28,"value":1472},"        return",{"type":23,"tag":71,"props":1474,"children":1475},{"style":94},[1476],{"type":28,"value":1077},{"type":23,"tag":71,"props":1478,"children":1479},{"style":104},[1480],{"type":28,"value":1082},{"type":23,"tag":71,"props":1482,"children":1483},{"style":183},[1484],{"type":28,"value":1087},{"type":23,"tag":71,"props":1486,"children":1487},{"style":104},[1488],{"type":28,"value":1489},"];\n",{"type":23,"tag":71,"props":1491,"children":1492},{"class":73,"line":300},[1493],{"type":23,"tag":71,"props":1494,"children":1495},{"style":104},[1496],{"type":28,"value":1497},"    }\n",{"type":23,"tag":71,"props":1499,"children":1500},{"class":73,"line":337},[1501,1506,1511,1515,1519,1523,1527,1531,1535,1539],{"type":23,"tag":71,"props":1502,"children":1503},{"style":78},[1504],{"type":28,"value":1505},"    else",{"type":23,"tag":71,"props":1507,"children":1508},{"style":78},[1509],{"type":28,"value":1510}," if",{"type":23,"tag":71,"props":1512,"children":1513},{"style":104},[1514],{"type":28,"value":1331},{"type":23,"tag":71,"props":1516,"children":1517},{"style":183},[1518],{"type":28,"value":1336},{"type":23,"tag":71,"props":1520,"children":1521},{"style":584},[1522],{"type":28,"value":931},{"type":23,"tag":71,"props":1524,"children":1525},{"style":183},[1526],{"type":28,"value":581},{"type":23,"tag":71,"props":1528,"children":1529},{"style":104},[1530],{"type":28,"value":1155},{"type":23,"tag":71,"props":1532,"children":1533},{"style":584},[1534],{"type":28,"value":1353},{"type":23,"tag":71,"props":1536,"children":1537},{"style":183},[1538],{"type":28,"value":581},{"type":23,"tag":71,"props":1540,"children":1541},{"style":104},[1542],{"type":28,"value":849},{"type":23,"tag":71,"props":1544,"children":1545},{"class":73,"line":378},[1546],{"type":23,"tag":71,"props":1547,"children":1548},{"style":104},[1549],{"type":28,"value":1369},{"type":23,"tag":71,"props":1551,"children":1552},{"class":73,"line":386},[1553],{"type":23,"tag":71,"props":1554,"children":1555},{"style":600},[1556],{"type":28,"value":1557},"        \u002F\u002F Bit 31 = 1, bit 30 = 0 → index file\n",{"type":23,"tag":71,"props":1559,"children":1560},{"class":73,"line":423},[1561,1565,1569,1573,1577,1581],{"type":23,"tag":71,"props":1562,"children":1563},{"style":183},[1564],{"type":28,"value":1444},{"type":23,"tag":71,"props":1566,"children":1567},{"style":584},[1568],{"type":28,"value":628},{"type":23,"tag":71,"props":1570,"children":1571},{"style":183},[1572],{"type":28,"value":1289},{"type":23,"tag":71,"props":1574,"children":1575},{"style":584},[1576],{"type":28,"value":931},{"type":23,"tag":71,"props":1578,"children":1579},{"style":183},[1580],{"type":28,"value":740},{"type":23,"tag":71,"props":1582,"children":1583},{"style":104},[1584],{"type":28,"value":1170},{"type":23,"tag":71,"props":1586,"children":1587},{"class":73,"line":464},[1588,1592,1596],{"type":23,"tag":71,"props":1589,"children":1590},{"style":78},[1591],{"type":28,"value":1472},{"type":23,"tag":71,"props":1593,"children":1594},{"style":183},[1595],{"type":28,"value":878},{"type":23,"tag":71,"props":1597,"children":1598},{"style":104},[1599],{"type":28,"value":1170},{"type":23,"tag":71,"props":1601,"children":1603},{"class":73,"line":1602},15,[1604],{"type":23,"tag":71,"props":1605,"children":1606},{"style":104},[1607],{"type":28,"value":1497},{"type":23,"tag":71,"props":1609,"children":1611},{"class":73,"line":1610},16,[1612],{"type":23,"tag":71,"props":1613,"children":1614},{"style":78},[1615],{"type":28,"value":1616},"    else\n",{"type":23,"tag":71,"props":1618,"children":1620},{"class":73,"line":1619},17,[1621],{"type":23,"tag":71,"props":1622,"children":1623},{"style":104},[1624],{"type":28,"value":1369},{"type":23,"tag":71,"props":1626,"children":1628},{"class":73,"line":1627},18,[1629],{"type":23,"tag":71,"props":1630,"children":1631},{"style":600},[1632],{"type":28,"value":1633},"        \u002F\u002F No high bits set → main page file\n",{"type":23,"tag":71,"props":1635,"children":1637},{"class":73,"line":1636},19,[1638,1642,1646,1650],{"type":23,"tag":71,"props":1639,"children":1640},{"style":183},[1641],{"type":28,"value":1444},{"type":23,"tag":71,"props":1643,"children":1644},{"style":584},[1645],{"type":28,"value":628},{"type":23,"tag":71,"props":1647,"children":1648},{"style":183},[1649],{"type":28,"value":1289},{"type":23,"tag":71,"props":1651,"children":1652},{"style":104},[1653],{"type":28,"value":1170},{"type":23,"tag":71,"props":1655,"children":1657},{"class":73,"line":1656},20,[1658,1662,1667],{"type":23,"tag":71,"props":1659,"children":1660},{"style":78},[1661],{"type":28,"value":1472},{"type":23,"tag":71,"props":1663,"children":1664},{"style":183},[1665],{"type":28,"value":1666}," _mainFile",{"type":23,"tag":71,"props":1668,"children":1669},{"style":104},[1670],{"type":28,"value":1170},{"type":23,"tag":71,"props":1672,"children":1674},{"class":73,"line":1673},21,[1675],{"type":23,"tag":71,"props":1676,"children":1677},{"style":104},[1678],{"type":28,"value":1497},{"type":23,"tag":71,"props":1680,"children":1682},{"class":73,"line":1681},22,[1683],{"type":23,"tag":71,"props":1684,"children":1685},{"style":104},[1686],{"type":28,"value":470},{"type":23,"tag":24,"props":1688,"children":1689},{},[1690,1692,1698,1699,1705,1707,1713,1714,1720,1722,1728,1730,1735],{"type":28,"value":1691},"Note the ordering: ",{"type":23,"tag":47,"props":1693,"children":1695},{"className":1694},[],[1696],{"type":28,"value":1697},"CollectionPageMarker",{"type":28,"value":921},{"type":23,"tag":47,"props":1700,"children":1702},{"className":1701},[],[1703],{"type":28,"value":1704},"0xC000_0000",{"type":28,"value":1706},") is tested before ",{"type":23,"tag":47,"props":1708,"children":1710},{"className":1709},[],[1711],{"type":28,"value":1712},"IndexPageMarker",{"type":28,"value":921},{"type":23,"tag":47,"props":1715,"children":1717},{"className":1716},[],[1718],{"type":28,"value":1719},"0x8000_0000",{"type":28,"value":1721},") because collection pages have ",{"type":23,"tag":1723,"props":1724,"children":1725},"em",{},[1726],{"type":28,"value":1727},"both",{"type":28,"value":1729}," bits set. Testing for ",{"type":23,"tag":47,"props":1731,"children":1733},{"className":1732},[],[1734],{"type":28,"value":1712},{"type":28,"value":1736}," first would incorrectly match collection pages.",{"type":23,"tag":24,"props":1738,"children":1739},{},[1740,1742,1748],{"type":28,"value":1741},"The caller gets back the right ",{"type":23,"tag":47,"props":1743,"children":1745},{"className":1744},[],[1746],{"type":28,"value":1747},"IPageFile",{"type":28,"value":1749}," and the physical (de-encoded) page number. The routing is two comparisons and two bitmask operations — essentially free at runtime.",{"type":23,"tag":31,"props":1751,"children":1752},{},[],{"type":23,"tag":35,"props":1754,"children":1756},{"id":1755},"file-growth-aligntoblock",[1757,1759],{"type":28,"value":1758},"File Growth: ",{"type":23,"tag":47,"props":1760,"children":1762},{"className":1761},[],[1763],{"type":28,"value":1764},"AlignToBlock",{"type":23,"tag":24,"props":1766,"children":1767},{},[1768],{"type":28,"value":1769},"File re-sizing is expensive. Every time you extend a file the OS must update metadata, potentially zero-fill new pages, and may trigger a flush. Growing one page at a time is impractical.",{"type":23,"tag":24,"props":1771,"children":1772},{},[1773],{"type":28,"value":1774},"BLite grows files in aligned blocks:",{"type":23,"tag":61,"props":1776,"children":1778},{"code":1777,"language":64,"meta":7,"className":65,"style":7},"private static long AlignToBlock(long requiredLength, long blockSize = 1_048_576 \u002F* 1 MB *\u002F)\n{\n    if (requiredLength \u003C= 0) return blockSize;\n    long remainder = requiredLength % blockSize;\n    return remainder == 0 ? requiredLength : requiredLength + (blockSize - remainder);\n}\n",[1779],{"type":23,"tag":47,"props":1780,"children":1781},{"__ignoreMap":7},[1782,1848,1855,1898,1932,1997],{"type":23,"tag":71,"props":1783,"children":1784},{"class":73,"line":74},[1785,1789,1793,1798,1803,1807,1812,1817,1821,1825,1830,1834,1839,1844],{"type":23,"tag":71,"props":1786,"children":1787},{"style":78},[1788],{"type":28,"value":566},{"type":23,"tag":71,"props":1790,"children":1791},{"style":78},[1792],{"type":28,"value":86},{"type":23,"tag":71,"props":1794,"children":1795},{"style":78},[1796],{"type":28,"value":1797}," long",{"type":23,"tag":71,"props":1799,"children":1800},{"style":128},[1801],{"type":28,"value":1802}," AlignToBlock",{"type":23,"tag":71,"props":1804,"children":1805},{"style":104},[1806],{"type":28,"value":136},{"type":23,"tag":71,"props":1808,"children":1809},{"style":78},[1810],{"type":28,"value":1811},"long",{"type":23,"tag":71,"props":1813,"children":1814},{"style":94},[1815],{"type":28,"value":1816}," requiredLength",{"type":23,"tag":71,"props":1818,"children":1819},{"style":104},[1820],{"type":28,"value":180},{"type":23,"tag":71,"props":1822,"children":1823},{"style":78},[1824],{"type":28,"value":1811},{"type":23,"tag":71,"props":1826,"children":1827},{"style":94},[1828],{"type":28,"value":1829}," blockSize",{"type":23,"tag":71,"props":1831,"children":1832},{"style":584},[1833],{"type":28,"value":628},{"type":23,"tag":71,"props":1835,"children":1836},{"style":193},[1837],{"type":28,"value":1838}," 1_048_576",{"type":23,"tag":71,"props":1840,"children":1841},{"style":600},[1842],{"type":28,"value":1843}," \u002F* 1 MB *\u002F",{"type":23,"tag":71,"props":1845,"children":1846},{"style":104},[1847],{"type":28,"value":849},{"type":23,"tag":71,"props":1849,"children":1850},{"class":73,"line":100},[1851],{"type":23,"tag":71,"props":1852,"children":1853},{"style":104},[1854],{"type":28,"value":107},{"type":23,"tag":71,"props":1856,"children":1857},{"class":73,"line":110},[1858,1862,1866,1871,1876,1881,1885,1890,1894],{"type":23,"tag":71,"props":1859,"children":1860},{"style":78},[1861],{"type":28,"value":1326},{"type":23,"tag":71,"props":1863,"children":1864},{"style":104},[1865],{"type":28,"value":921},{"type":23,"tag":71,"props":1867,"children":1868},{"style":183},[1869],{"type":28,"value":1870},"requiredLength",{"type":23,"tag":71,"props":1872,"children":1873},{"style":584},[1874],{"type":28,"value":1875}," \u003C=",{"type":23,"tag":71,"props":1877,"children":1878},{"style":193},[1879],{"type":28,"value":1880}," 0",{"type":23,"tag":71,"props":1882,"children":1883},{"style":104},[1884],{"type":28,"value":1155},{"type":23,"tag":71,"props":1886,"children":1887},{"style":78},[1888],{"type":28,"value":1889},"return",{"type":23,"tag":71,"props":1891,"children":1892},{"style":183},[1893],{"type":28,"value":1829},{"type":23,"tag":71,"props":1895,"children":1896},{"style":104},[1897],{"type":28,"value":1170},{"type":23,"tag":71,"props":1899,"children":1900},{"class":73,"line":154},[1901,1906,1911,1915,1919,1924,1928],{"type":23,"tag":71,"props":1902,"children":1903},{"style":78},[1904],{"type":28,"value":1905},"    long",{"type":23,"tag":71,"props":1907,"children":1908},{"style":183},[1909],{"type":28,"value":1910}," remainder",{"type":23,"tag":71,"props":1912,"children":1913},{"style":584},[1914],{"type":28,"value":628},{"type":23,"tag":71,"props":1916,"children":1917},{"style":183},[1918],{"type":28,"value":1816},{"type":23,"tag":71,"props":1920,"children":1921},{"style":584},[1922],{"type":28,"value":1923}," %",{"type":23,"tag":71,"props":1925,"children":1926},{"style":183},[1927],{"type":28,"value":1829},{"type":23,"tag":71,"props":1929,"children":1930},{"style":104},[1931],{"type":28,"value":1170},{"type":23,"tag":71,"props":1933,"children":1934},{"class":73,"line":204},[1935,1939,1943,1948,1952,1957,1961,1966,1970,1975,1979,1984,1989,1993],{"type":23,"tag":71,"props":1936,"children":1937},{"style":78},[1938],{"type":28,"value":907},{"type":23,"tag":71,"props":1940,"children":1941},{"style":183},[1942],{"type":28,"value":1910},{"type":23,"tag":71,"props":1944,"children":1945},{"style":584},[1946],{"type":28,"value":1947}," ==",{"type":23,"tag":71,"props":1949,"children":1950},{"style":193},[1951],{"type":28,"value":1880},{"type":23,"tag":71,"props":1953,"children":1954},{"style":104},[1955],{"type":28,"value":1956}," ? ",{"type":23,"tag":71,"props":1958,"children":1959},{"style":183},[1960],{"type":28,"value":1870},{"type":23,"tag":71,"props":1962,"children":1963},{"style":104},[1964],{"type":28,"value":1965}," : ",{"type":23,"tag":71,"props":1967,"children":1968},{"style":183},[1969],{"type":28,"value":1870},{"type":23,"tag":71,"props":1971,"children":1972},{"style":584},[1973],{"type":28,"value":1974}," +",{"type":23,"tag":71,"props":1976,"children":1977},{"style":104},[1978],{"type":28,"value":921},{"type":23,"tag":71,"props":1980,"children":1981},{"style":183},[1982],{"type":28,"value":1983},"blockSize",{"type":23,"tag":71,"props":1985,"children":1986},{"style":584},[1987],{"type":28,"value":1988}," -",{"type":23,"tag":71,"props":1990,"children":1991},{"style":183},[1992],{"type":28,"value":1910},{"type":23,"tag":71,"props":1994,"children":1995},{"style":104},[1996],{"type":28,"value":201},{"type":23,"tag":71,"props":1998,"children":1999},{"class":73,"line":214},[2000],{"type":23,"tag":71,"props":2001,"children":2002},{"style":104},[2003],{"type":28,"value":470},{"type":23,"tag":24,"props":2005,"children":2006},{},[2007],{"type":28,"value":2008},"When the storage engine needs a new page and the file isn't large enough, it rounds up the required length to the next 1 MB boundary and resizes in one shot. The new pages in the gap are initialized with a reserved \"empty page\" marker. This reduces the frequency of OS-level resize operations by roughly three orders of magnitude for typical workloads.",{"type":23,"tag":31,"props":2010,"children":2011},{},[],{"type":23,"tag":35,"props":2013,"children":2015},{"id":2014},"memory-mapped-files-in-net",[2016],{"type":28,"value":2017},"Memory-Mapped Files in .NET",{"type":23,"tag":24,"props":2019,"children":2020},{},[2021,2023,2029],{"type":28,"value":2022},"BLite uses ",{"type":23,"tag":47,"props":2024,"children":2026},{"className":2025},[],[2027],{"type":28,"value":2028},"MemoryMappedFile",{"type":28,"value":2030}," for all page I\u002FO:",{"type":23,"tag":61,"props":2032,"children":2034},{"code":2033,"language":64,"meta":7,"className":65,"style":7},"_mmf = MemoryMappedFile.CreateFromFile(\n    fileStream,\n    mapName:    null,\n    capacity:   alignedSize,\n    access:     MemoryMappedFileAccess.ReadWrite,\n    inheritability: HandleInheritability.None,\n    leaveOpen:  true\n);\n_accessor = _mmf.CreateViewAccessor(0, alignedSize, MemoryMappedFileAccess.ReadWrite);\n",[2035],{"type":23,"tag":47,"props":2036,"children":2037},{"__ignoreMap":7},[2038,2069,2082,2103,2125,2156,2187,2205,2212],{"type":23,"tag":71,"props":2039,"children":2040},{"class":73,"line":74},[2041,2046,2050,2055,2059,2064],{"type":23,"tag":71,"props":2042,"children":2043},{"style":183},[2044],{"type":28,"value":2045},"_mmf",{"type":23,"tag":71,"props":2047,"children":2048},{"style":584},[2049],{"type":28,"value":628},{"type":23,"tag":71,"props":2051,"children":2052},{"style":94},[2053],{"type":28,"value":2054}," MemoryMappedFile",{"type":23,"tag":71,"props":2056,"children":2057},{"style":104},[2058],{"type":28,"value":170},{"type":23,"tag":71,"props":2060,"children":2061},{"style":128},[2062],{"type":28,"value":2063},"CreateFromFile",{"type":23,"tag":71,"props":2065,"children":2066},{"style":104},[2067],{"type":28,"value":2068},"(\n",{"type":23,"tag":71,"props":2070,"children":2071},{"class":73,"line":100},[2072,2077],{"type":23,"tag":71,"props":2073,"children":2074},{"style":183},[2075],{"type":28,"value":2076},"    fileStream",{"type":23,"tag":71,"props":2078,"children":2079},{"style":104},[2080],{"type":28,"value":2081},",\n",{"type":23,"tag":71,"props":2083,"children":2084},{"class":73,"line":110},[2085,2090,2095,2099],{"type":23,"tag":71,"props":2086,"children":2087},{"style":94},[2088],{"type":28,"value":2089},"    mapName",{"type":23,"tag":71,"props":2091,"children":2092},{"style":104},[2093],{"type":28,"value":2094},":    ",{"type":23,"tag":71,"props":2096,"children":2097},{"style":193},[2098],{"type":28,"value":196},{"type":23,"tag":71,"props":2100,"children":2101},{"style":104},[2102],{"type":28,"value":2081},{"type":23,"tag":71,"props":2104,"children":2105},{"class":73,"line":154},[2106,2111,2116,2121],{"type":23,"tag":71,"props":2107,"children":2108},{"style":94},[2109],{"type":28,"value":2110},"    capacity",{"type":23,"tag":71,"props":2112,"children":2113},{"style":104},[2114],{"type":28,"value":2115},":   ",{"type":23,"tag":71,"props":2117,"children":2118},{"style":183},[2119],{"type":28,"value":2120},"alignedSize",{"type":23,"tag":71,"props":2122,"children":2123},{"style":104},[2124],{"type":28,"value":2081},{"type":23,"tag":71,"props":2126,"children":2127},{"class":73,"line":204},[2128,2133,2138,2143,2147,2152],{"type":23,"tag":71,"props":2129,"children":2130},{"style":94},[2131],{"type":28,"value":2132},"    access",{"type":23,"tag":71,"props":2134,"children":2135},{"style":104},[2136],{"type":28,"value":2137},":     ",{"type":23,"tag":71,"props":2139,"children":2140},{"style":94},[2141],{"type":28,"value":2142},"MemoryMappedFileAccess",{"type":23,"tag":71,"props":2144,"children":2145},{"style":104},[2146],{"type":28,"value":170},{"type":23,"tag":71,"props":2148,"children":2149},{"style":94},[2150],{"type":28,"value":2151},"ReadWrite",{"type":23,"tag":71,"props":2153,"children":2154},{"style":104},[2155],{"type":28,"value":2081},{"type":23,"tag":71,"props":2157,"children":2158},{"class":73,"line":214},[2159,2164,2169,2174,2178,2183],{"type":23,"tag":71,"props":2160,"children":2161},{"style":94},[2162],{"type":28,"value":2163},"    inheritability",{"type":23,"tag":71,"props":2165,"children":2166},{"style":104},[2167],{"type":28,"value":2168},": ",{"type":23,"tag":71,"props":2170,"children":2171},{"style":94},[2172],{"type":28,"value":2173},"HandleInheritability",{"type":23,"tag":71,"props":2175,"children":2176},{"style":104},[2177],{"type":28,"value":170},{"type":23,"tag":71,"props":2179,"children":2180},{"style":94},[2181],{"type":28,"value":2182},"None",{"type":23,"tag":71,"props":2184,"children":2185},{"style":104},[2186],{"type":28,"value":2081},{"type":23,"tag":71,"props":2188,"children":2189},{"class":73,"line":251},[2190,2195,2200],{"type":23,"tag":71,"props":2191,"children":2192},{"style":94},[2193],{"type":28,"value":2194},"    leaveOpen",{"type":23,"tag":71,"props":2196,"children":2197},{"style":104},[2198],{"type":28,"value":2199},":  ",{"type":23,"tag":71,"props":2201,"children":2202},{"style":193},[2203],{"type":28,"value":2204},"true\n",{"type":23,"tag":71,"props":2206,"children":2207},{"class":73,"line":292},[2208],{"type":23,"tag":71,"props":2209,"children":2210},{"style":104},[2211],{"type":28,"value":201},{"type":23,"tag":71,"props":2213,"children":2214},{"class":73,"line":300},[2215,2220,2224,2229,2233,2238,2242,2247,2251,2255,2259,2263,2267,2271],{"type":23,"tag":71,"props":2216,"children":2217},{"style":183},[2218],{"type":28,"value":2219},"_accessor",{"type":23,"tag":71,"props":2221,"children":2222},{"style":584},[2223],{"type":28,"value":628},{"type":23,"tag":71,"props":2225,"children":2226},{"style":94},[2227],{"type":28,"value":2228}," _mmf",{"type":23,"tag":71,"props":2230,"children":2231},{"style":104},[2232],{"type":28,"value":170},{"type":23,"tag":71,"props":2234,"children":2235},{"style":128},[2236],{"type":28,"value":2237},"CreateViewAccessor",{"type":23,"tag":71,"props":2239,"children":2240},{"style":104},[2241],{"type":28,"value":136},{"type":23,"tag":71,"props":2243,"children":2244},{"style":193},[2245],{"type":28,"value":2246},"0",{"type":23,"tag":71,"props":2248,"children":2249},{"style":104},[2250],{"type":28,"value":180},{"type":23,"tag":71,"props":2252,"children":2253},{"style":183},[2254],{"type":28,"value":2120},{"type":23,"tag":71,"props":2256,"children":2257},{"style":104},[2258],{"type":28,"value":180},{"type":23,"tag":71,"props":2260,"children":2261},{"style":94},[2262],{"type":28,"value":2142},{"type":23,"tag":71,"props":2264,"children":2265},{"style":104},[2266],{"type":28,"value":170},{"type":23,"tag":71,"props":2268,"children":2269},{"style":94},[2270],{"type":28,"value":2151},{"type":23,"tag":71,"props":2272,"children":2273},{"style":104},[2274],{"type":28,"value":201},{"type":23,"tag":24,"props":2276,"children":2277},{},[2278,2280,2286,2288,2294],{"type":28,"value":2279},"Memory-mapped files let the OS kernel manage the page cache. Reading a page doesn't require a ",{"type":23,"tag":47,"props":2281,"children":2283},{"className":2282},[],[2284],{"type":28,"value":2285},"Read",{"type":28,"value":2287}," syscall — the page maps directly into the process's virtual address space and is demand-paged from disk on first access. Write-back is also handled by the OS: modified pages are flushed to disk when the OS decides to, or explicitly via ",{"type":23,"tag":47,"props":2289,"children":2291},{"className":2290},[],[2292],{"type":28,"value":2293},"_accessor.Flush()",{"type":28,"value":170},{"type":23,"tag":24,"props":2296,"children":2297},{},[2298,2300,2305],{"type":28,"value":2299},"This gives BLite zero-copy reads and the full benefit of OS-level I\u002FO scheduling. The trade-off: you can't easily control ",{"type":23,"tag":1723,"props":2301,"children":2302},{},[2303],{"type":28,"value":2304},"when",{"type":28,"value":2306}," dirty pages are flushed, which is why the WAL exists — durability is guaranteed by the log, not by the memory-mapped file.",{"type":23,"tag":31,"props":2308,"children":2309},{},[],{"type":23,"tag":35,"props":2311,"children":2313},{"id":2312},"immutable-configuration-record-struct-with-with",[2314,2316,2322,2324],{"type":28,"value":2315},"Immutable Configuration: ",{"type":23,"tag":47,"props":2317,"children":2319},{"className":2318},[],[2320],{"type":28,"value":2321},"record struct",{"type":28,"value":2323}," with ",{"type":23,"tag":47,"props":2325,"children":2327},{"className":2326},[],[2328],{"type":28,"value":2329},"with",{"type":23,"tag":24,"props":2331,"children":2332},{},[2333,2335,2340,2342,2347],{"type":28,"value":2334},"Page file configuration is represented as a ",{"type":23,"tag":47,"props":2336,"children":2338},{"className":2337},[],[2339],{"type":28,"value":2321},{"type":28,"value":2341}," — value semantics, immutable by convention, copy-on-modification via ",{"type":23,"tag":47,"props":2343,"children":2345},{"className":2344},[],[2346],{"type":28,"value":2329},{"type":28,"value":538},{"type":23,"tag":61,"props":2349,"children":2351},{"code":2350,"language":64,"meta":7,"className":65,"style":7},"public readonly record struct Config\n{\n    public Mode DeploymentMode { get; init; }\n    public string DatabasePath { get; init; }\n    public string? MapName { get; init; }\n\n    \u002F\u002F Example: create a server config with a custom map name\n    public Config WithMapName(string mapName) => this with { MapName = mapName };\n}\n",[2352],{"type":23,"tag":47,"props":2353,"children":2354},{"__ignoreMap":7},[2355,2382,2389,2425,2458,2490,2497,2505,2567],{"type":23,"tag":71,"props":2356,"children":2357},{"class":73,"line":74},[2358,2362,2367,2372,2377],{"type":23,"tag":71,"props":2359,"children":2360},{"style":78},[2361],{"type":28,"value":81},{"type":23,"tag":71,"props":2363,"children":2364},{"style":78},[2365],{"type":28,"value":2366}," readonly",{"type":23,"tag":71,"props":2368,"children":2369},{"style":78},[2370],{"type":28,"value":2371}," record",{"type":23,"tag":71,"props":2373,"children":2374},{"style":78},[2375],{"type":28,"value":2376}," struct",{"type":23,"tag":71,"props":2378,"children":2379},{"style":94},[2380],{"type":28,"value":2381}," Config\n",{"type":23,"tag":71,"props":2383,"children":2384},{"class":73,"line":100},[2385],{"type":23,"tag":71,"props":2386,"children":2387},{"style":104},[2388],{"type":28,"value":107},{"type":23,"tag":71,"props":2390,"children":2391},{"class":73,"line":110},[2392,2396,2401,2406,2411,2415,2420],{"type":23,"tag":71,"props":2393,"children":2394},{"style":78},[2395],{"type":28,"value":116},{"type":23,"tag":71,"props":2397,"children":2398},{"style":94},[2399],{"type":28,"value":2400}," Mode",{"type":23,"tag":71,"props":2402,"children":2403},{"style":104},[2404],{"type":28,"value":2405}," DeploymentMode { ",{"type":23,"tag":71,"props":2407,"children":2408},{"style":78},[2409],{"type":28,"value":2410},"get",{"type":23,"tag":71,"props":2412,"children":2413},{"style":104},[2414],{"type":28,"value":597},{"type":23,"tag":71,"props":2416,"children":2417},{"style":78},[2418],{"type":28,"value":2419},"init",{"type":23,"tag":71,"props":2421,"children":2422},{"style":104},[2423],{"type":28,"value":2424},"; }\n",{"type":23,"tag":71,"props":2426,"children":2427},{"class":73,"line":154},[2428,2432,2437,2442,2446,2450,2454],{"type":23,"tag":71,"props":2429,"children":2430},{"style":78},[2431],{"type":28,"value":116},{"type":23,"tag":71,"props":2433,"children":2434},{"style":78},[2435],{"type":28,"value":2436}," string",{"type":23,"tag":71,"props":2438,"children":2439},{"style":104},[2440],{"type":28,"value":2441}," DatabasePath { ",{"type":23,"tag":71,"props":2443,"children":2444},{"style":78},[2445],{"type":28,"value":2410},{"type":23,"tag":71,"props":2447,"children":2448},{"style":104},[2449],{"type":28,"value":597},{"type":23,"tag":71,"props":2451,"children":2452},{"style":78},[2453],{"type":28,"value":2419},{"type":23,"tag":71,"props":2455,"children":2456},{"style":104},[2457],{"type":28,"value":2424},{"type":23,"tag":71,"props":2459,"children":2460},{"class":73,"line":204},[2461,2465,2469,2474,2478,2482,2486],{"type":23,"tag":71,"props":2462,"children":2463},{"style":78},[2464],{"type":28,"value":116},{"type":23,"tag":71,"props":2466,"children":2467},{"style":78},[2468],{"type":28,"value":2436},{"type":23,"tag":71,"props":2470,"children":2471},{"style":104},[2472],{"type":28,"value":2473},"? MapName { ",{"type":23,"tag":71,"props":2475,"children":2476},{"style":78},[2477],{"type":28,"value":2410},{"type":23,"tag":71,"props":2479,"children":2480},{"style":104},[2481],{"type":28,"value":597},{"type":23,"tag":71,"props":2483,"children":2484},{"style":78},[2485],{"type":28,"value":2419},{"type":23,"tag":71,"props":2487,"children":2488},{"style":104},[2489],{"type":28,"value":2424},{"type":23,"tag":71,"props":2491,"children":2492},{"class":73,"line":214},[2493],{"type":23,"tag":71,"props":2494,"children":2495},{"emptyLinePlaceholder":208},[2496],{"type":28,"value":211},{"type":23,"tag":71,"props":2498,"children":2499},{"class":73,"line":251},[2500],{"type":23,"tag":71,"props":2501,"children":2502},{"style":600},[2503],{"type":28,"value":2504},"    \u002F\u002F Example: create a server config with a custom map name\n",{"type":23,"tag":71,"props":2506,"children":2507},{"class":73,"line":292},[2508,2512,2516,2521,2525,2529,2534,2539,2544,2549,2554,2558,2562],{"type":23,"tag":71,"props":2509,"children":2510},{"style":78},[2511],{"type":28,"value":116},{"type":23,"tag":71,"props":2513,"children":2514},{"style":94},[2515],{"type":28,"value":125},{"type":23,"tag":71,"props":2517,"children":2518},{"style":128},[2519],{"type":28,"value":2520}," WithMapName",{"type":23,"tag":71,"props":2522,"children":2523},{"style":104},[2524],{"type":28,"value":136},{"type":23,"tag":71,"props":2526,"children":2527},{"style":78},[2528],{"type":28,"value":141},{"type":23,"tag":71,"props":2530,"children":2531},{"style":94},[2532],{"type":28,"value":2533}," mapName",{"type":23,"tag":71,"props":2535,"children":2536},{"style":104},[2537],{"type":28,"value":2538},") => ",{"type":23,"tag":71,"props":2540,"children":2541},{"style":94},[2542],{"type":28,"value":2543},"this",{"type":23,"tag":71,"props":2545,"children":2546},{"style":104},[2547],{"type":28,"value":2548}," with { ",{"type":23,"tag":71,"props":2550,"children":2551},{"style":183},[2552],{"type":28,"value":2553},"MapName",{"type":23,"tag":71,"props":2555,"children":2556},{"style":584},[2557],{"type":28,"value":628},{"type":23,"tag":71,"props":2559,"children":2560},{"style":183},[2561],{"type":28,"value":2533},{"type":23,"tag":71,"props":2563,"children":2564},{"style":104},[2565],{"type":28,"value":2566}," };\n",{"type":23,"tag":71,"props":2568,"children":2569},{"class":73,"line":300},[2570],{"type":23,"tag":71,"props":2571,"children":2572},{"style":104},[2573],{"type":28,"value":470},{"type":23,"tag":24,"props":2575,"children":2576},{},[2577,2582,2584,2590,2591,2597,2599,2605,2607,2612,2614,2620],{"type":23,"tag":47,"props":2578,"children":2580},{"className":2579},[],[2581],{"type":28,"value":2321},{"type":28,"value":2583}," is a C# 10 feature. It generates ",{"type":23,"tag":47,"props":2585,"children":2587},{"className":2586},[],[2588],{"type":28,"value":2589},"Equals",{"type":28,"value":180},{"type":23,"tag":47,"props":2592,"children":2594},{"className":2593},[],[2595],{"type":28,"value":2596},"GetHashCode",{"type":28,"value":2598},", and ",{"type":23,"tag":47,"props":2600,"children":2602},{"className":2601},[],[2603],{"type":28,"value":2604},"ToString",{"type":28,"value":2606}," based on the fields, and the ",{"type":23,"tag":47,"props":2608,"children":2610},{"className":2609},[],[2611],{"type":28,"value":2329},{"type":28,"value":2613}," expression creates a copy with one field changed without mutating the original. This is useful for test setup: start from ",{"type":23,"tag":47,"props":2615,"children":2617},{"className":2616},[],[2618],{"type":28,"value":2619},"PageFileConfig.Embedded(path)",{"type":28,"value":2621}," and derive variants for specific test scenarios without shared mutable state.",{"type":23,"tag":31,"props":2623,"children":2624},{},[],{"type":23,"tag":35,"props":2626,"children":2628},{"id":2627},"concrete-limits",[2629],{"type":28,"value":2630},"Concrete Limits",{"type":23,"tag":24,"props":2632,"children":2633},{},[2634],{"type":28,"value":2635},"The encoding imposes hard limits worth knowing before committing to BLite:",{"type":23,"tag":2637,"props":2638,"children":2639},"table",{},[2640,2664],{"type":23,"tag":2641,"props":2642,"children":2643},"thead",{},[2644],{"type":23,"tag":2645,"props":2646,"children":2647},"tr",{},[2648,2654,2659],{"type":23,"tag":2649,"props":2650,"children":2651},"th",{},[2652],{"type":28,"value":2653},"Resource",{"type":23,"tag":2649,"props":2655,"children":2656},{},[2657],{"type":28,"value":2658},"Limit",{"type":23,"tag":2649,"props":2660,"children":2661},{},[2662],{"type":28,"value":2663},"Why",{"type":23,"tag":2665,"props":2666,"children":2667},"tbody",{},[2668,2687,2705,2723],{"type":23,"tag":2645,"props":2669,"children":2670},{},[2671,2677,2682],{"type":23,"tag":2672,"props":2673,"children":2674},"td",{},[2675],{"type":28,"value":2676},"Collections per database",{"type":23,"tag":2672,"props":2678,"children":2679},{},[2680],{"type":28,"value":2681},"64",{"type":23,"tag":2672,"props":2683,"children":2684},{},[2685],{"type":28,"value":2686},"6-bit slot in bits 29–24",{"type":23,"tag":2645,"props":2688,"children":2689},{},[2690,2695,2700],{"type":23,"tag":2672,"props":2691,"children":2692},{},[2693],{"type":28,"value":2694},"Pages per collection file",{"type":23,"tag":2672,"props":2696,"children":2697},{},[2698],{"type":28,"value":2699},"16,777,215",{"type":23,"tag":2672,"props":2701,"children":2702},{},[2703],{"type":28,"value":2704},"24-bit local page number",{"type":23,"tag":2645,"props":2706,"children":2707},{},[2708,2713,2718],{"type":23,"tag":2672,"props":2709,"children":2710},{},[2711],{"type":28,"value":2712},"Pages per index file",{"type":23,"tag":2672,"props":2714,"children":2715},{},[2716],{"type":28,"value":2717},"536,870,911",{"type":23,"tag":2672,"props":2719,"children":2720},{},[2721],{"type":28,"value":2722},"30-bit local page number (bit 31 claims one)",{"type":23,"tag":2645,"props":2724,"children":2725},{},[2726,2731,2735],{"type":23,"tag":2672,"props":2727,"children":2728},{},[2729],{"type":28,"value":2730},"Pages per main file",{"type":23,"tag":2672,"props":2732,"children":2733},{},[2734],{"type":28,"value":2717},{"type":23,"tag":2672,"props":2736,"children":2737},{},[2738],{"type":28,"value":2739},"Same, no high bits consumed",{"type":23,"tag":24,"props":2741,"children":2742},{},[2743],{"type":28,"value":2744},"At 4 KB per page, a single collection file can hold up to 64 GB of data. Exceeding that limit requires a schema migration to split the collection across multiple databases, which BLite doesn't yet automate.",{"type":23,"tag":31,"props":2746,"children":2747},{},[],{"type":23,"tag":35,"props":2749,"children":2751},{"id":2750},"what-id-do-differently",[2752],{"type":28,"value":2753},"What I'd Do Differently",{"type":23,"tag":24,"props":2755,"children":2756},{},[2757],{"type":28,"value":2758},"The 64-collection limit is the most likely pain point in practice. A 7-bit slot field (128 collections) would change the encoding but all existing databases would be incompatible — a schema migration is unavoidable either way. Doing this sooner rather than later is the right call.",{"type":23,"tag":24,"props":2760,"children":2761},{},[2762,2764,2769],{"type":28,"value":2763},"The per-collection file growth allocates 1 MB at a time, which is reasonable for large collections but wastes space for databases with many small collections. A per-file configurable block size would help, at the cost of more complexity in ",{"type":23,"tag":47,"props":2765,"children":2767},{"className":2766},[],[2768],{"type":28,"value":1764},{"type":28,"value":170},{"type":23,"tag":24,"props":2771,"children":2772},{},[2773,2775,2780,2782,2787],{"type":28,"value":2774},"The server mode is currently a stub — the routing code exists but the remote I\u002FO transport does not. If you're using BLite today, ",{"type":23,"tag":47,"props":2776,"children":2778},{"className":2777},[],[2779],{"type":28,"value":175},{"type":28,"value":2781}," and ",{"type":23,"tag":47,"props":2783,"children":2785},{"className":2784},[],[2786],{"type":28,"value":269},{"type":28,"value":2788}," are the only production-ready modes.",{"type":23,"tag":31,"props":2790,"children":2791},{},[],{"type":23,"tag":35,"props":2793,"children":2795},{"id":2794},"the-bottom-line",[2796],{"type":28,"value":2797},"The Bottom Line",{"type":23,"tag":24,"props":2799,"children":2800},{},[2801,2803,2808],{"type":28,"value":2802},"Encoding file type, collection slot, and local page number into a ",{"type":23,"tag":47,"props":2804,"children":2806},{"className":2805},[],[2807],{"type":28,"value":536},{"type":28,"value":2809}," is one of those ideas that looks clever until you realize it's just two bitmask checks and some bit-shifts. The result is a routing layer with no heap allocations, no dictionary lookups, and O(1) dispatch from any page ID to the right physical file.",{"type":23,"tag":24,"props":2811,"children":2812},{},[2813,2815,2824],{"type":28,"value":2814},"The complete source is on ",{"type":23,"tag":2816,"props":2817,"children":2821},"a",{"href":2818,"rel":2819},"https:\u002F\u002Fgithub.com\u002FEntglDb\u002FBLite",[2820],"nofollow",[2822],{"type":28,"value":2823},"GitHub",{"type":28,"value":170},{"type":23,"tag":2826,"props":2827,"children":2828},"style",{},[2829],{"type":28,"value":2830},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":7,"searchDepth":100,"depth":100,"links":2832},[2833,2834,2835,2837,2839,2840,2842,2843,2844],{"id":37,"depth":100,"text":40},{"id":522,"depth":100,"text":525},{"id":1238,"depth":100,"text":2836},"The Router: GetPageFile",{"id":1755,"depth":100,"text":2838},"File Growth: AlignToBlock",{"id":2014,"depth":100,"text":2017},{"id":2312,"depth":100,"text":2841},"Immutable Configuration: record struct with with",{"id":2627,"depth":100,"text":2630},{"id":2750,"depth":100,"text":2753},{"id":2794,"depth":100,"text":2797},"markdown","content:en:blog:bitwise-page-routing-blite-storage-engine.md","content","en\u002Fblog\u002Fbitwise-page-routing-blite-storage-engine.md","en\u002Fblog\u002Fbitwise-page-routing-blite-storage-engine","md",{"loc":4},1775332618206]