-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doc request: How does emscripten MEMFS persist link information in IDBFS? #15789
Comments
I believe you need to use IDBFS (not MEMFS) if you want to persist the data. According the docs here it looks like the way to do as of today is to call |
When you use IDBFS, all data is stored in memory... maybe not memfs exactly, though that would seem wasteful to not re-use it. My question was how it persists the link information when it does that operation. Like... looking through the IDBFS database, I wasn't easily able to find what was a link and what wasn't. |
This issue in SO is related. |
@DavidGOrtega are you sure you are using |
Hey @sbc100 , yes Im using Module.onRuntimeInitialized = () => {
const IDBFS = FS.filesystems.IDBFS;
const path = '/IDBFS'
FS.mkdir(path);
FS.mount(IDBFS, {}, path);
FS.chdir(path);
FS.syncfs(true, (err) => {
console.log(err);
});
I would like to init the filesystem within my C++ code and wait there for the filesystem to be ready but Im not sure how to accomplish it EM_ASM({
const IDBFS = FS.filesystems.IDBFS;
const path = $0;
FS.mkdir(path);
FS.mount(IDBFS, {}, path);
FS.chdir(path);
FS.syncfs(true, (err) => {
// now we can continue with the C++ class constructor or factory
});
}, path); |
This is what I was puzzled about. |
@DavidGOrtega and @hcldan, do you see this same behavior of the IndexedDB files not being listed, despite being present, in Chrome or other browsers? I've seen the behavior you describe with my own code if I use Firefox with URL GET parameters. Inspector doesn't show the IndexedDB entries when I specify a URL with GET parameters. If I leave off the GET parameters, the entries are shown. Chrome doesn't behave this way. So far, I've seen no issues related to file size, though the files I've used haven't been particularly large. The single largest file I've worked with was about 35 megs. As for using IDBFS, I'll share the methodology that's worked for me. When I start my program, I want to make sure that files are immediately available for use, so I've created a main.js where I call
Here's my main.js:
@DavidGOrtega mentions wanting to initiate the Lastly, if you have any interest in allowing a user to upload local files into IndexedDB, I recently posted something about that in #18306. If you have any questions, I'll try to help as best I can. Jeff |
@jhirschberg70 thanks a lot for the reply 🙏
Mine can be many of many GB
Awesome suggestion! I did not know it. Could you please point me where to find the docs? Im struggling a bit with the emscripten docs. I.E. I don't yet know how to properly create a Worker to run in another thread like a would do with Napi. |
My main issue was that I could see the files listed but I had no idea how to inspect the file contents (or if indeed there were any file contents) from the chrome tool inspector. Which is why I was asking how it was stored... maybe it's just a dev tool issue? I haven't looked in a while since support for OPFS high performance handles landed. |
You're welcome, @DavidGOrtega. Are you saying that your constructor uses the filesystem? If so, then why does it matter whether you sync in JavaScript or C++? Either way you're going to have to wait for the sync to complete. Am I misunderstanding?
If you have to sync files that are multiple GBs, then I can understand how that could be bad for the user, but again, I don't see how where you initiate the sync (JS or C++) affects things. The problem is that you have to sync and that sync is going to have to copy many GBs to memory.
Here's a link to the section of the docs that talks about If you don't want to use a Promise wrapped around Apparently, there's a more elegant solution for waiting on JS from C++ without using a There are also the Asynchronous File System API and Asynchronous IndexedDB API, which might be useful for you. I have no experience with these. https://emscripten.org/docs/api_reference/emscripten.h.html#asynchronous-file-system-api https://emscripten.org/docs/api_reference/emscripten.h.html?highlight=idb_store#asynchronous-indexeddb-api I haven't done anything with pthreads, so I can't help with that. My work with workers has been limited to some very basic experiments, so I don't think I can give much insight there, either. Jeff |
@hcldan, do you mean something other than the Jeff |
Yes. I don't recall ever finding that back then, but this was exactly what I was looking for. |
Please include the following in your bug report:
I asked this question on SO and was suggested to ask for an update to the docs.
https://stackoverflow.com/questions/70368027/how-does-emscripten-memfs-persist-link-information-in-idbfs
The text was updated successfully, but these errors were encountered: