-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
refactor: asynchronous blob backing store #10969
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great that you started on this!
There needs to be some changes to file backed blobs, mainly that they should not use the standard Deno FS APIs, as those go via regular permission checks. Instead there should be some ops in Rust that can only write files to a specific tmp dir, and can only access these files (and nothing else on disk). To JS they would only be exposed as UUIDs. These ops would not require any permissions. I can add these ops if you don't feel comfortable with Rust or the deno ops system.
Additionally we need to figure out what our metric for creating file based blobs is. We always know the size of a blob at creation, so do automatically create a file backed blob if the blob is larger than a specific threshold? Do we create blobs once we have used a fixed amount of memory for blob backing memory allocations in the process? File backed blobs should be fully transparent to the user. They should have no knowledge of them existing.
As you mentioned, FormData currently synchronously reads from Blob. This is not possible anymore with file backed blobs, so the entire FormData serializer needs to be turned into something that returns either a ReadableStream or an async iterable of chunks. Additionally URL.createObjectURL
also synchronously reads from Blob - that also needs to be updated. That will require some changes to how object url blobs are stored in Rust.
Yes plz, thank you. I have never worked with rust before.
EDIT: Not at the moment. But it could be a grate idea to offload some of the memory to a tmp file in the background if they are not being used. But could instead do that in a new feature PR. Have manly just focus on getting support for async blob sources. Currently don't see offloading chunks as a huge benefit ATM. mainly wanted to be able to get a Blob/File from a filesystem and use them in FormData and other places That was the main reason why I added the
...Or a blob 🙃 #10969 (comment) ☝️
Again, would like to leave this up to you. haven't worked with Rust before. It would need references points i guess... Will fix all you reviews |
reverted some webidl, spec step
A couple months ago I worked on putting together a spec definition of |
Oh, speaking of serializing FormData boundary. On bad thing the blob spec is doing is lowercasing the hole mimetype See: whatwg/html#6251 when, blob cast the type to all lowercase it looses it boundary value, and it's no longer the same I guess they are planing on only lowercasing the mimetype + keys (but keeping the values as is) we (in fetch-blob) also did this lowercase but removed it to be less strict I think we should do this in the meanwhile: - return normalizedType.toLowerCase();
+ return normalizedType; |
@jimmywarting Are you on the Deno discord (https://discord.gg/deno)? I have a basic implementation of the Rust side for this done, but have some questions - might be easier to chat there than through GitHub issues / PR review :-) |
@lucacasonato yes I'm |
provided a util fn to retrieve all BlobReferences as a flat array for createObjectURL Hold the parts in a WeakMap instead to access them from outside Removed BlobDataItem (mostly do same thing as BlobReferences)
The remaining test failure is an issue with an upstream WPT test. PR: web-platform-tests/wpt#29517 |
Blocked on denoland/rusty_v8#706 for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks a lot @jimmywarting, this is a fantastic great refactor to prepare us for the native file system API, and opaque file backed blobs.
@bartlomieju could you take a look too?
This is my first time trying to contribute and learn the in and outs of how deno works internally - so be kind and helpful plz
I haven't learn how to fully work with all linting, (WPT) tests, webidl and what you can/can't do. And i do not know anything about rust, so i'm thankful for lucacasonato help on this PR.
Trying to solve some of the discussion that have been going on in #10539
Realized that i broke FormData encoder that is reading from the (now removed)
_byteSequence
- but it's fixed nowURL.createObjectURL also depended on
_byteSequence
- have also been refactored on the Rust sideAlso did some manually testing on the new getFile() fn seems to work out nicely.Got replaced \w BlobReferences - still missing
BlobReferences.fromPath
doeBlobReferences
when Blob's are GC'ed withFinalizationRegistry
FinalizationRegistry
supportNon essential for a MVP:
BlobReferences#stream
method directly from RustBlobReferences
from a filePath (needed for New File System API #11018) (Permission check ???)