mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-25 20:14:21 +01:00
The page cache implementation uses a pre-allocated vector (`entries`) with fixed capacity, along with a custom hash map and freelist. This design requires expensive upfront allocation when creating a new connection, which severely impacted performance in workloads that open many short-lived connections (e.g., our concurrent write benchmarks that create a new connection per transaction). Therefore, replace the pre-allocated vector with an intrusive doubly- linked list. This eliminates the page cache initialization overhead from connection establishment, but also reduces memory usage to entries that are actually used. Furthermore, the approach allows us to grow the page cache with much less overhead. The patch improves concurrent write throughput benchmark by 4x for single-threaded performance. Before: ``` $ write-throughput --threads 1 --batch-size 100 -i 1000 --mode concurrent Running write throughput benchmark with 1 threads, 100 batch size, 1000 iterations, mode: Concurrent Database created at: write_throughput_test.db Thread 0: 100000 inserts in 3.82s (26173.63 inserts/sec) ``` After: ``` $ write-throughput --threads 1 --batch-size 100 -i 1000 --mode concurrent Running write throughput benchmark with 1 threads, 100 batch size, 1000 iterations, mode: Concurrent Database created at: write_throughput_test.db Thread 0: 100000 inserts in 0.90s (110848.46 inserts/sec) ``` Closes #3456