数据库写入测试
在浏览器中比较按时间排序的 ID(ULID 或 UUID v7)与随机 UUID v4 的 IndexedDB 写入速度。仅为本地测量,不是已发布的实验室结果。
Database Index Insertion Benchmark
Compare database index writing performance between Sequential IDs (ULIDs / UUID v7) and Random IDs (UUID v4) using IndexedDB.
Time-Sorted Sequential IDs (ULID / UUID v7)
IdleUnsorted Random IDs (UUID v4)
IdleIndex Insertion Cost Curve
This graph plots transaction latency (ms) for consecutive database insert operations. Notice how random inserts trigger B-Tree page splits, causing latency spikes.
Why is there a performance difference?
Modern databases (such as IndexedDB, SQLite, PostgreSQL, and MySQL) store primary keys inside a B-Tree or B+Tree index structure. When you insert sequential IDs (ULIDs, UUID v7), new records are always appended to the right-most edge of the index, requiring zero re-balancing. In contrast, random IDs (UUID v4) must be inserted at arbitrary nodes, forcing the database to frequently split data pages, move physical sectors, and fragment the index, resulting in slow writes and high storage space overhead.