Closed Bug 806374 Opened 12 years ago Closed 11 years ago

Don't store phone's wallpaper or the dialer ringtone or the notification ringtone as a data: URI in the settings DB

Categories

(Firefox OS Graveyard :: Gaia::Settings, defect)

x86
macOS
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: justin.lebar+bug, Assigned: fabrice)

References

Details

(Keywords: perf, Whiteboard: [MemShrink:P2][c=performance])

Attachments

(2 files, 6 obsolete files)

Filed based on bug 802446 comment 16.

I don't know how much memory we're wasting here, but it seems like we may not want to store the phone's wallpaper as a data: URI in the settings DB because

* data: URIs are 2.7x larger than blobs
* all access to the settings DB is proxied through the main process (apparently?), so the main process uses memory (at least temporarily) to support this image.

Can we so something smarter here?
Since the wallpaper is managed by the system app, we can probably just move the image file into the system app resources and reference it.
(In reply to Fabrice Desré [:fabrice] from comment #1)
> Since the wallpaper is managed by the system app, we can probably just move
> the image file into the system app resources and reference it.

The homescreen app is the one which actually displays the wallpaper, right?  Under that scheme, how would we transfer the wallpaper from the system app to the homescreen app?
No, the system app displays the wallpaper afaict. Just try by killing the homescreen ;)
Whiteboard: [MemShrink] → [MemShrink:P2]
(In reply to Fabrice Desré [:fabrice] from comment #3)
> No, the system app displays the wallpaper afaict. Just try by killing the
> homescreen ;)

You are right, but the image files must be shared between: system app/settings app/wallpaper app.
And what you said in comment 2 is what system app had done early before.
Sorry is comment 1.
(In reply to Fabrice Desré [:fabrice] from comment #1)
> Since the wallpaper is managed by the system app, we can probably just move
> the image file into the system app resources and reference it.

If we do so, we couldn't set a photo captured by the camera but only the static images in the system app.
Data URIs are also being used to store ringtones in settings.

Beyond the single copy stored directly, you can end up with additional copies of these giant strings getting copied around.  For instance, in this B2G log I have, it looks like we have 4 copies of the wallpaper floating around, one inside the CSP cache...
Component: Gaia → Gaia::Settings
Summary: Don't store phone's wallpaper as a data: URI in the settings DB → Don't store phone's wallpaper or the dialer ringtone or the notification ringtone as a data: URI in the settings DB
Attached patch gecko patch (obsolete) — Splinter Review
This patch converts all data: uris that are using when calling set() to blobs. This means that when doing a get() of the setting, we need to check if its a blob and get the blob uri.
Assignee: nobody → fabrice
Attachment #781058 - Flags: feedback?(anygregor)
Attached patch gaia patch v1 (obsolete) — Splinter Review
The gaia side of the conversion. I still have to do the ringtones, but this patch should take care of all the wallpaper use.
Attachment #781059 - Flags: review?
Attached patch gaia patch v2 (obsolete) — Splinter Review
Hopefully with the notification and dialer ringtones also fixed.
Attachment #781059 - Attachment is obsolete: true
Attachment #781059 - Flags: review?
Surely you need to revoke this object URL at some point?
(In reply to Justin Lebar [:jlebar] from comment #10)
> Surely you need to revoke this object URL at some point?

Ideally yes (if not they are cleared when the document disappears), but I don't know how to do that for css background images.
Otherwise every time you change the background, we'll leak the old blob permanently, in the main process, right?
Attached patch gaia patch v3 (obsolete) — Splinter Review
Now trying to revoke URL.
Attachment #781082 - Attachment is obsolete: true
Attached patch gecko patch v2Splinter Review
Update of the previous patch to convert data: uris in all object properties, and to also do it in the SettingsService.
Attachment #781058 - Attachment is obsolete: true
Attachment #781058 - Flags: feedback?(anygregor)
Attachment #782372 - Flags: review?(anygregor)
Attached patch gaia patch v4 (obsolete) — Splinter Review
This patch let us use either urls or blobs for the wallpaper and ringtones settings. I also changed the wallpaper saving in the settings app to not do a blob -> data uri anymore.

Tim & Vivien, feel free to redirect the review. I just don't know who to ask.
Attachment #781328 - Attachment is obsolete: true
Attachment #782374 - Flags: review?(timdream)
Attachment #782374 - Flags: review?(21)
Comment on attachment 782372 [details] [diff] [review]
gecko patch v2

Review of attachment 782372 [details] [diff] [review]:
-----------------------------------------------------------------

Looks good to me. The only thing missing is a testcase :)

::: dom/settings/SettingsDB.jsm
@@ +166,5 @@
> +        let start = aValue.indexOf(",") + 1;
> +        let isBase64 = ((aValue.indexOf("base64") + 7) == start);
> +        let payload = aValue.substring(start);
> +
> +        return new Blob([isBase64 ?base64DecToArr(payload) : payload],

nit: space after ?

@@ +175,5 @@
> +    }
> +    return aValue
> +  },
> +
> +  // Makes sure any propery that is a data: uri gets converted to a Blob.

nit: property

@@ +189,5 @@
> +      return aObject
> +    } else if (kind == "blob") {
> +      return aObject
> +    } else if (kind == "date") {
> +      return aObject

maybe combine file, blob, date and add ';' after aObject

@@ +194,5 @@
> +    } else if (kind == "primitive") {
> +      return this.convertDataURIToBlob(aObject);
> +    }
> +
> +    // Fall-through, we now have a dictionnary object.

nit: dictionary
Attachment #782372 - Flags: review?(anygregor) → review+
Try build with nits addressed and a test added (based on the blobs tests, but storing a data: uri instead of a blob) :
https://tbpl.mozilla.org/?tree=Try&rev=77de3bb69ddd
Comment on attachment 782374 [details] [diff] [review]
gaia patch v4

Review of attachment 782374 [details] [diff] [review]:
-----------------------------------------------------------------

To be honest I'm a bit concerned about memory leaks.

Also the code seems really similar in so many places. What about a little shared/js/ file to centralize that?
Attached patch gaia patch v5 (obsolete) — Splinter Review
Everything looks fine in my testing. We'll need to land that before the gecko patch as it supports both blobs and plain text uris.
Attachment #782374 - Attachment is obsolete: true
Attachment #782374 - Flags: review?(timdream)
Attachment #782374 - Flags: review?(21)
Attachment #783536 - Flags: review?(21)
Comment on attachment 783536 [details] [diff] [review]
gaia patch v5

Review of attachment 783536 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks.
Attachment #783536 - Flags: review?(21) → review+
backed out of gaia for now:
https://github.com/mozilla-b2g/gaia/commit/8ae9100dd47e13a655423191cb3b3e5a02c5388a

I don't have any context here but this was breaking the travis build somehow.
Blocks: 902559
https://github.com/mozilla-b2g/gaia/pull/11431/files#r5667602

Additionally, the SettingsURL constructor needs unit tests before it can be used in the Messages app.
Looks like I am taking over and getting this landed. Rick - I'll try to address your concerns before we land. Thanks.
Assignee: fabrice → kgrandon
Status: NEW → ASSIGNED
Keywords: perf
Whiteboard: [MemShrink:P2] → [MemShrink:P2][c=performance]
Gaia part has landed in master: https://github.com/mozilla-b2g/gaia/commit/845abbb2ae4802c1fe50a50336dac922536a329d
Assignee: kgrandon → fabrice
Attached file gaia patch v6
The landed patch had a few minor differences than v5. Obsoleting the old patch in case someone needs this.
Attachment #783536 - Attachment is obsolete: true
please see https://github.com/mozilla-b2g/gaia/commit/90245e0e244063545b83f6b1f21279a04bb077d4#commitcomment-3828736 as I added some recommendation to do the SettingsURL abstraction right. Thanks !
Fabrice - Would you have any comment on Julien's comment above?
Flags: needinfo?(fabrice)
I commented on github.
Flags: needinfo?(fabrice)
Depends on: 903760
Filed bug 903760 for further work.
https://hg.mozilla.org/mozilla-central/rev/c521aae575b5
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Depends on: 903260
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: