VFS benchmarks (including the official SQLite WASM OPFS VFS) #86
rhashimoto
started this conversation in
Show and tell
Replies: 2 comments 1 reply
-
Re. the OSW timing variance: try the same thing on the OSW with the dev tools open and you may see the times triple (or more) even though no console output is generated. Why that happens is unclear but it's reliably observable in Chrome. |
Beta Was this translation helpful? Give feedback.
1 reply
-
It is interesting! Here are the method call counts: AccessHandlePoolVFS
OSW
My notes:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have been measuring the performance of AccessHandlePoolVFS against other VFS classes - some from wa-sqlite and also the offical SQLite WASM OPFS VFS (OSW henceforth). The SQL for the benchmarks can be found in the .sql files here, and they are based on an old SQLite benchmarks page I originally discussed here.
Here are timings (in seconds) on my 2014 Mac mini and its SSD using Chrome 112:
I ran the benchmarks three times for OSW OPFS (shown in three columns) just to provide a feel for the variance in the timings.
My initial attempts at timing OSW had it running faster than AccessHandlePoolVFS, which didn't make sense to me. A little digging uncovered a dangerous OSW synchronization bug (fixed immediately after I reported it) which wasn't waiting for the journal to be written before modifying the database. If you want to play with OSW yourself make sure to get a version with the fix.
I wouldn't regard these numbers as absolute truth - it's an artificial workload on one particular browser and machine, implemented by a fallible developer - but here are some of my notes:
The setup SQL shown attempts to provide the same conditions for all the VFS implementations. AccessHandlePoolVFS doesn't support multiple connections, so it makes sense to let all implementations optimize for a single connection with locking_mode=exclusive (it's still possible to allow multiple contexts to share a single connection at the application level). Page size and cache largely determines the number of calls made to the VFS. The database file size for this example is just less than 8 MB, so that is where I set the cache size. IDBBatchAtomicVFS also uses the cache for its journal so it might be disadvantaged by this, but I considered that more fair than setting the cache size higher than the other implementations could actually use.
AccessHandlePoolVFS beats OriginPrivateFileSystemVFS on every benchmark except one which I consider a tie. OriginPrivateFileSystemVFS does allow concurrent reads (the other OPFS implementations do not), so that's an advantage not shown here, but AccessHandlePoolVFS wins the read benchmarks (Test 4, 5, and 7) by 2-4x so that's the amount of concurrency needed to break even. I think the circumstances where OriginPrivateFileSystemVFS could be the best choice are going to be pretty rare, so I'm not going to discuss it further here (and I'm not planning to update it going forward).
AccessHandlePoolVFS is about even with OSW on some benchmarks and a bit faster on others. It seems to do the best on the benchmarks with the most statements (Test 2, 3, 7, 9, and 10) whether reading or writing. If the benchmarks are set up correctly, both implementations should be executing exactly the same VFS calls, so the expected difference is that OSW proxies some calls over SharedArrayBuffer and AccessHandlePoolVFS does not. OSW's own analysis estimates that overhead at 40% (obviously on a different machine than mine), which is roughly in the same ballpark. I'm not fully confident in that as the explanation, though, because the benchmarks with the most VFS calls (and thus the most per-call overhead) aren't necessarily the ones with the most SQL statements. It might be interesting to count the number of calls to each method to see whether that correlation holds up.
IDBBatchAtomicVFS dominates Test 1, which emphasizes write transaction costs. The likely reason for this has to do with how SQLite exploits filesystem guarantees and is explained here. It gets even better - another order of magnitude better - in relaxed durability mode (which still preserves atomicity and consistency), also discussed earlier. IDBBatchAtomicVFS loses all the other benchmarks to both AccessHandlePoolVFS and OSW except Test 16. IDBBatchAtomicVFS does support concurrent reads, but it has a very similar breakeven point against AccessHandlePoolVFS as OriginPrivateFileSystemVFS.
Beta Was this translation helpful? Give feedback.
All reactions