whisper.cpp icon indicating copy to clipboard operation
whisper.cpp copied to clipboard

Consider using OPFS instead of IndexedDB for storage in WASM demos

Open bgrins opened this issue 2 years ago • 5 comments

OPFS has some nice properties - better persistence, performance, and consistent support for large files across browsers (enabling Firefox support for the larger models).

Would you be open to a change to helpers.js to migrate the backend or do you prefer to stick with IndexedDB?

bgrins avatar Apr 27 '23 03:04 bgrins

Yes, if this fixes Firefox support then we should use it

ggerganov avatar Apr 29 '23 07:04 ggerganov

Sounds good. Depending on how things are accessed, the Cache API in a Service Worker may be a solution to consider as well https://developer.mozilla.org/en-US/docs/Web/API/Cache. I believe this would allow the helper code like loadRemote to always just call fetch() and deal with the Response - with the first time causing a remote fetch and subsequent requests being served from a local cache. This is "best-effort" like IndexedDB which means it could be evicted without notice, but I think would be comparable to the behavior today.

bgrins avatar May 03 '23 20:05 bgrins

Thanks @bgrins for highlighting this - was straightforward for me to replace IndexedDB with OPFS for caching. Here is a Gist from code snippets that worked for me - maybe it helps someone else. Feel free to use it - I might contribute it back in a few weeks.

https://gist.github.com/tudi2d/ea79d717c1fe27f23f09e66b3f0663cf

tudi2d avatar Sep 16 '23 15:09 tudi2d

Thanks @bgrins for highlighting this - was straightforward for me to replace IndexedDB with OPFS for caching. Here is a Gist from code snippets that worked for me - maybe it helps someone else. Feel free to use it - I might contribute it back in a few weeks.

https://gist.github.com/tudi2d/ea79d717c1fe27f23f09e66b3f0663cf

But createWritable is not supported in safari. Do we have any work around for that

vpbs2 avatar Nov 13 '23 19:11 vpbs2

Thanks @bgrins for highlighting this - was straightforward for me to replace IndexedDB with OPFS for caching. Here is a Gist from code snippets that worked for me - maybe it helps someone else. Feel free to use it - I might contribute it back in a few weeks. https://gist.github.com/tudi2d/ea79d717c1fe27f23f09e66b3f0663cf

But createWritable is not supported in safari. Do we have any work around for that

you can use the sync worker api in Safari, Firefox and Chrome: https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system#manipulating_the_opfs_from_a_web_worker

chee avatar Jun 06 '24 11:06 chee