Open Bug 1384622 Opened 7 years ago Updated 2 years ago

consider making Blob handle Cache API body streams better

Categories

(Core :: DOM: File, enhancement, P3)

enhancement

Tracking

()

People

(Reporter: bkelly, Unassigned)

References

(Blocks 1 open bug)

Details

Currently this code:

  let cache = await caches.open(db);
  let response = await cache.match(req);
  let blob = await response.blob();

Will read the Cache API body off disk, into memory, and then may spill back to a temporary file.  This is a bit wasteful since the Cache body stream is already on disk.

In theory we could QI to Cache's ReadStream type (confusing name now that we have js ReadableStream as well.)  If its a cache::ReadStream then it could adopt the stream and wait to consume it until later.  Depending on how the Blob is used we may never have to read it off disk or we can just read it sequentially.

Unfortunately the Blob cannot just treat the Cache body as flat file, though.  We do compress Cache bodies on disk using snappy.  This means cache::ReadStream would also have to provide a "absolute length" getter so blob could know the total length.

On the other hand, maybe this is too complex for the payoff.  If code is going to use the blob we need to read it eventually.  Maybe doing that eagerly is best.

Just something to think about.
We can implement a SnappyBlobImpl yes. We just need a type, a size and a file path.

But Cache API is able to provide a nsIInputStream, we can simply use a StreamBlobImpl. Also here we need a type and a size.

Question: what about if the cache entry is removed in the meantime? I guess we have to keep the blob, the stream or the snappy blob impl alive and working until it is released.
(In reply to Andrea Marchesini [:baku] from comment #1)
> Question: what about if the cache entry is removed in the meantime? I guess
> we have to keep the blob, the stream or the snappy blob impl alive and
> working until it is released.

This is already handled by ReadStream.  It implements actors to ref-count the open stream in the parent side.
Priority: -- → P2
Moving to p3 because no activity for at least 1 year(s).
See https://github.com/mozilla/bug-handling/blob/master/policy/triage-bugzilla.md#how-do-you-triage for more information
Priority: P2 → P3
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.