Le 19/04/2014 02:58, Jonas Sicking a écrit :
On Fri, Apr 18, 2014 at 6:12 AM, Julien Wajsberg <[email protected]> wrote:
On Wed, Apr 16, 2014 at 10:45 AM, ben turner <[email protected]>
wrote:

---------- Forwarded message ----------
From: Julien Wajsberg <[email protected]>
Date: Wed, Apr 16, 2014 at 9:30 AM
Subject: [b2g] Using blobs to display images
To: dev-b2g <[email protected]>


Hey,

Basically, I'd like to know whether it's better to revoke a blob URL
just after an image has been loaded, even if it's still displayed, or to
keep the blob url valid until the image is hidden.
tl;dr: You should revoke it when the onload or onerror events fire.
Ok, I see that I forgot one important bit of information: I'm actually
concerned about background images. For normal images in <img> it's easy to
do in onerror/onload.

I tried to do clever things like loading asychronously (after setTimeout) an
in-memory image with the same blob url and discarding at onload/onerror but
this randomly fails.

The "best" solution I have right now is to put a timer of say 30 seconds and
revoke the URL then, but I'm afraid to retain memory in case of memory
pressure. But maybe that's good enough?
Ouch, yeah, this is a bit of a problem.

At the very least you can revoke the URL when we stop displaying the
image. I.e. if we change the background to some other URL, or if that
part of the UI is completely hidden

Yes that's also a possibility I had in mind. Aren't we taking up valuable memory if you keep the blob url valid? Or is that memory used anyway, because the image is displayed, and as a result it would not take more than what's already taken?

  (I don't know what piece of UI
that we're talking about here).

We're doing this in 2 parts of the UI:

* displaying contacts pictures. This currently comes from the mozContacts API only. But for Facebook contacts this will eventually come from a Datastore or a local IDB as well. We might even do a local IDB for all contact's source too, in the future.

* displaying attachments. Until very recently, we were generating thumbnails using the canvas API, and export them as data url, and use this as background-image. In bug 996516 we'll take advantage of the downsamping url feature to use directly the blob url in this. The data comes from the mozMobileMessage API, and from activities.

In both cases, using background-image brings us the ratio-aware property background-size. It brings us also background-position which we don't use yet but could be useful to properly position a contact's face. Probably if we had the same possibility for usual images we could use them instead (even if in the contact picture case, a background image looks more semantic).


However it would also be good to have some sort of event fired once
layout code has fully loaded any resources that it depends on, such as
background images. However I just talked to dbaron and he pointed out
that this would be of pretty narrow functionality since it wouldn't
necessarily mean that the page is ready to be painted (asynchronous
image decoding might still need to happen), and it also wouldn't work
in cases where we avoid doing image loads for images that are outside
of the current visible part of the page.

Does that mean that revoking after 30 seconds would not work either in some situations?


Another solution here would be if we added support for URLs that map
directly into indexedDB. See

http://lists.w3.org/Archives/Public/public-webapps/2013JulSep/0081.html

Would that cross process boundaries? I guess not, and so would not be that useful for us.

Thanks !
--
Julien

_______________________________________________
dev-b2g mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-b2g

Reply via email to