New demos for OPFS access handle #84
Replies: 2 comments 7 replies
-
I went down a rabbit hole trying to figure this out. First I wrote a micro-benchmark to time a bunch of OPFS writes and flushes to verify that was indeed where the difference was. Then I went on a long internet journey, and found that Chrome has a special flush implementation on Apple devices. Instead of calling if (!HANDLE_EINTR(fcntl(file_.get(), F_FULLFSYNC)))
return true; What does F_FULLFSYNC do? Basically it does what
I haven't been able to confirm how Firefox and Safari do syncing, but I strongly suspect that they aren't using F_FULLFSYNC. That would obviously be a serious bug, right? Maybe not. At one time, the lack of using F_FULLFSYNC on Mac was actually filed as a Firefox bug, but it was eventually marked WONTFIX. One of the commenters on the bug is Dr. Richard Hipp, the author of SQLite:
So even Apple doesn't use F_FULLFSYNC and the SQLite folks don't recommend it (at least not back in 2008); it can be enabled in SQLite (on a native Apple build) with a pragma, but the default is off. This SQLite forum message reports that interrupting SQLite connections not using F_FULLFSYNC could affect durability but did not find any database corruption with the specific devices and software versions tested. It appears that all the browsers are making an informed decision about the risks and rewards here and have arrived at different conclusions, and that's the reason why Chrome is dramatically slower on OPFS flush (and therefore on OPFS VFS write transactions) on macOS and iOS. Application developers considering an OPFS VFS should be aware that:
|
Beta Was this translation helpful? Give feedback.
-
First of all: I really appreciate your fantastic work on all of this! Looks like you've recently shipped v1.0 (congrats!) and as part of the preparations deleted the above-mentioned ahp demos as part of #174. Are there any plans to bring those back? @rhashimoto |
Beta Was this translation helpful? Give feedback.
-
There are a couple new demos showing off a synthesis of two ideas that have their own discussion threads:
Combining these ideas makes possible an OPFS-backed database service that:
The new demos are really just copies of existing demos, except using a shared connection to AccessHandlePoolVFS for database queries:
Both of these demos use the same SharedService name, so you can open multiple browser tabs of both and they all will share a single database connection. That means, for example, that after running a contention test you can compose SQL to dig deeper into the results, say to see if the same tab ever gets consecutive transactions.
Note that these demos are implemented with ES6 module Worker (because I'm too lazy to bundle them), which is enabled by default in Firefox nightly. You can run on Firefox beta and stable by enabling
dom.workers.modules.enabled
at about:config, but you may need to avoid this recently fixed bug. The demos work fine on the current versions of Safari and Chrome (and I assume other Chromium-based browsers, e.g. Edge).Early (and possibly premature) conclusions from these demos:
Shared AHP contention results on my 2014 Mac mini on various browsers for 1, 8, and 32 (!) browser tabs:
Beta Was this translation helpful? Give feedback.
All reactions