cr-sqlite: Fix, or work around, Safari optimization problems

Reported by @Azarattum

https://discord.com/channels/989870439897653248/989870440585494530/1119945592970424500

More context: https://github.com/rhashimoto/wa-sqlite/discussions/94

I can’t reproduce this problem with the official SQLite WASM (OSW) build. Given that, my assumption is that is because they do not use asyncify.

Adopting OSW would be a bit problematic given their reliance on shared array buffer.

A better option would be to use the AccessHandlePoolVFS (https://github.com/rhashimoto/wa-sqlite/blob/007f3553564654096403dddc9c54adbf57feadc0/src/examples/AccessHandlePoolVFS.js#L36) assuming this does not break Safari either.

Next steps:

  • Try to repro the problem with AccessHandlePoolVFS
  • If it does not repro, use AccessHandlePoolVFS and coordinate message ports with ServiceWorker if possible, SharedWorker otherwise

Switching to AccessHandlePoolVFS will create quite a bit of work for us on the react integration side. Since we will now have to communicate over a message port to a worker, we’ll need to find a new way to batch useQuery hooks into a single tick of the event loop.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 17 (3 by maintainers)

Commits related to this issue

Most upvoted comments

@rhashimoto, I think your tip saved me an entire week of work 😃

If you or @Azarattum ever want to compare notes on building web apps with SQLite there are a few of us (@schickling, @geoffreylitt) trying to push the boundaries of SQLite.

@rhashimoto - the -O3 suggestion seems to work.

CPU maxes out at ~300% rather than ~500% and only for a couple of seconds rather than the 30+.

Binary size only changed by a few KB which was surprising.

@Azarattum I’ll roll a new release with this change that you can test with.

Screenshot 2023-07-06 at 11 15 03 AM

@quolpr - I only tried O3.

@rhashimoto - it works on the 2 iPhones and 1 iPad I’ve tested against.

Haven’t filed the webkit issue yet but it is on the todo list for this week.