mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-28 21:44:21 +01:00
### Problem Profiling revealed that `usable_space()` calls were consuming 60% of total execution time for simple SELECT queries, making Limbo approximately `6x` slower than SQLite for SELECT operations. The bottleneck was caused by `usable_space()` performing expensive I/O operations on every call to read `page_size` and `reserved_space` from the database header, despite `page_size` values being effectively immutable after database initialization. Only `reserved_space` is allowed to increase in SQLite. Evidence: https://share.firefox.dev/44tCUIy ### Solution Implemented OnceCell-based caching for both page_size and reserved_space values in the Pager struct: `page_size: OnceCell<u16>` - Page size is immutable after database initialization per SQLite specification `reserved_space: OnceCell<u8>` - Reserved space rarely changes and only grows, safe to cache ### Performance Impact Benchmark results: Simple SELECT query time reduced from ~2.89ms to ~1.29ms (~55% improvement) Closes #1852