Closed Bug 815173 Opened 14 years ago Closed 13 years ago

The interface feels sluggish when installing a big app

Categories

(Firefox OS Graveyard :: General, defect, P3)

All
Gonk (Firefox OS)
defect

Tracking

(blocking-basecamp:+, firefox19 fixed, firefox20 fixed, b2g18 fixed)

VERIFIED FIXED
blocking-basecamp +
Tracking Status
firefox19 --- fixed
firefox20 --- fixed
b2g18 --- fixed

People

(Reporter: julienw, Assigned: gsvelto)

References

Details

Attachments

(1 file, 1 obsolete file)

STR: * go to http://owapps.cloudfoundry.com with Firefox * install the big packaged app * play with the notification panel (displaying it, hiding it, etc) => the animations are sluggish I suspect this is because we're modifying the DOM at each progress event. We should update it only once per second (or per 500ms). We could either do this rate limit in gaia or in platform.
blocking-basecamp: --- → ?
Blocks: app-install
There are several reasons why this might be slow. We should profile[1] to find out what the culprit is. This is almost certainly related to bug 813765 . [1] https://developer.mozilla.org/en-US/docs/Performance/Profiling_with_the_Built-in_Profiler#Profiling_Boot_to_Gecko_%28with_a_real_device%29
Hmm...so the app size here is about 8.3 MB. That's definitely within our range of support (marketplace currently limits packaged app size to 50 MB or lower).
blocking-basecamp: ? → +
Priority: -- → P3
Benoit, could you get us the profile for this? Then we can deal with it
Assignee: nobody → bgirard
Flags: needinfo?(bgirard)
Looks to me like painting was slow. We spent: 8% on layout 8% on flush style 8% on flush layout 10% waiting on the compositor 30% of painting the page.
Benoit, can you see if the sluggish feel could come from the fact that we're actually waiting before painting, for example because the HTTP download is in the main thread for now ?
The only waiting I saw was us waiting on events. I profiled this work on the b2g process. I'm not familiar with what happens on which process. What process do you expect this download to be in?
All network activity happens in the chrome process, but all network data is shipped to the content process as well if it initiated the download.
I'm not familiar at all with this, that was an idea from Vivien, maybe he'll be able to explain better tomorrow. However, I still think that updating the DOM for each progress is wrong. Are your data confirming this ?
Updating the DOM in many events is fine as long as you don't query position information each time which will cause many flush. The engine will track the modifications and will coalesce them using the refresh driver. I'm not sure if I reproduced the same problem you saw. When we click the install button we we're taken to the home screen where we saw a rotating circle shape. We saw maybe 2 200ms-ish jerk in the animation but nothing substantial. Is this what you saw?
During the download, you can try to play with the notification panel (displaying it, hiding it, etc), sliding the homescreen panels, etc. All the animations are jerky. I didn't pay attention so much to the rotating circle shape..
And that's right that we don't flush at each right, but I thought that just accessing the DOM from JavaScript was already slow... and here it happens many times per second.
Alright I took profiles of each process and I noticed that the dropdown notification is janky while the circle shape spinner isn't. http://people.mozilla.com/~bgirard/cleopatra/#report=537de474b08d9429f73c30ab2c5992b62f5f1ed3 Looks like we are causing a synchronous flush from here which is expensive: ut_onTouchStart() @ utility_tray.js:87 View: http://people.mozilla.com/~bgirard/cleopatra/#report=537de474b08d9429f73c30ab2c5992b62f5f1ed3&search=ut_onTouchStart%28%29%2520%2540%2520utility_tray.js I'm not convinced we're seeing everything. The other process were not showing anything interesting.
So what are the next steps ? We're still not sure it is related to Bug 813765 ?
Flags: needinfo?(fabrice)
Flags: needinfo?(fabrice)
Run it through triage with this extra info.
blocking-basecamp: + → ?
This is the line causing the reflow: this.screen.classList.add('utility-tray'); Gaia could try to toggle the touch behavior without adding to the classList and avoid the style flush.
Doug is going to plus this and reassign it.
Assignee: bgirard → nobody
blocking-basecamp: ? → +
Flags: needinfo?(mwu)
gsvelto is going to try his hand at profiling this. vingetun suggested timdream to look at eliminating a reflow as suggested in comment 16. Tim, what do you think?
Flags: needinfo?(mwu) → needinfo?(timdream+bugs)
Let's get this assigned to gsvelto asap. And, let's get a confirmation gsvelto is on it, please.
<gsvelto> mwu: it looks like they do have a few leads already, I'll run it through the profiler myself to see if I can spot something else
Assignee: nobody → gsvelto
(In reply to Michael Wu [:mwu] from comment #18) > gsvelto is going to try his hand at profiling this. > > vingetun suggested timdream to look at eliminating a reflow as suggested in > comment 16. Tim, what do you think? That reflow is legit; we need the class name not just toggling the behavior but also rearrange the UI with CSS. Unless that is the _sole_ reason that caused the slowness ...
Flags: needinfo?(timdream+bugs)
I did some profiling plus some heuristic testing by keeping an eye on what was happening on the phone using top to isolate the biggest CPU consumers during the installation. What I noticed was that the main b2g process would burn ~50-60% CPU time with the Homescreen taking another ~30%. If you look at the profiles for both applications side-by-side you'll notice that painting is an issue in both (with flushing right behind): they're burning respectively 30% and 60% of their time doing it. (I'd love to post both profiles but I'm having an issue with cleopatra upload functionality, it's not giving me a link to the trace after the upload has finished) However I've discovered another interesting bit and I'll dig deeper into it: I've tried switching to the calculator app during the installation. The app was slow but usable, what was interesting however was that when I went back to the Homescreen it got stuck on the wallpaper for ~20s before repainting the icons. I've tried it a couple of times and I have the feeling that the homescreen gets to repaint itself only after the installation has finished, in the meantime it's completely stuck. Since the delay is so long I'll try to break in with gdb while it's happening to figure out where it gets stuck, maybe it'll give us some hints of what's wrong. As for the painting, I want to try disabling the homescreen animation to see how it affects the overall behavior.
While experimenting I've noticed a behavior I have a hard time to reproduce: sometimes the progress bar in the tray shows the animated icon under gaia/apps/system/style/shared/progress.gif instead of an actual bar. However I couldn't figure out what's causing it, it just happens from time to time. Anyway I've tried disabling that animation by replacing the animated gif with a static one as well as removing the animation attribute of the app icon spinner and then re-running the profile. Both the homescreen and the utility tray remained very choppy; this suggests that the animations are making the problem worse but are not causing it directly. Here is the full profile for the main b2g process (consuming ~60% CPU time): http://people.mozilla.com/~bgirard/cleopatra/#report=4c984a8cccb362429d8a9253bf0fdd97a731c98f And this is the homescreen process (consuming ~20% CPU time): http://people.mozilla.com/~bgirard/cleopatra/#report=89d1d2fbc161b829b7f856a8aeebad45e688089a And here is a zoomed set of samples while the installation was going on in the main b2g process: http://people.mozilla.com/~bgirard/cleopatra/#report=33761ce11c24f9913c35bd1a92713fe65462364f As you can see a disproportionate amount of time is now being spent in Webapps.js receiveMessage() method. Most of the time actually goes into the various child functions but we're calling receiveMessage() at least every 50ms. That might just be too often for the amount of work it triggers. From the profile I cannot peek into the message being received but I wouldn't be surprised if it's installState/downloadprogress. If you look carefully you'll see that this is mirrored by a huge amount of time spent in a Webapps.jsm broadcastMessage() call triggered by nsHttpChannel::OnDataAvailable(). Similarly this is the homescreen process: http://people.mozilla.com/~bgirard/cleopatra/#report=8836876081ee0ffc2b5f11d113c4b9542fb46241 Now that there's no repainting going on it's actually waiting most of the time, but it's being woken up every 30-40ms by what seems an incoming message (Webapps.js receiveMessage() again). There doesn't seem to be many layout::Flush() calls however so I'm assuming that re-layouts being triggered is not the root cause either. From the looks of it my feeling is that we're just sending too many updates while downloading an app; reducing the number of updates should alleviate the problem. I'd like to confirm this by actually counting the number of events per second being sent, I'll post again with numbers ASAP.
After tracing the messages I've reconstructed this chain of events: - nsHttpChannel::OnDataAvailable() is firing as fast as it can, sometimes only after having received a single packet (~1500 bytes of data) - Webapps.jsm is listening to that event and triggering process notifications, this is generating a lot of work for broadcasting the messages as well as generating more work on the receive side when these messages trigger non-trivial event handlers - If the amount of work done by each listener is reduced (by disabling animations for example) nsHttpChannel::OnDataAvailable() fires more events (as the kernel is buffering less data between recv() calls) and the total load on the phone is essentially unchanged with the main b2g process eating up all free CPU cycles My conclusion is that we probably want to throttle the amount of notifications being set from Webapps.jsm, more specifically here: http://mxr.mozilla.org/mozilla-central/source/dom/apps/src/Webapps.jsm#1708 If I read it correctly onProgress() is being called for every nsHttpChannel::OnDataAvailable event and broadcasting a Webapps:PackageEvent/progress message which is the root of the problem. Throttling the amount of notifications sent out (5 second? More?) should solve the issue.
gsvelto> thanks for this great work. I was basically suggesting this in my bug report ;) Fabrice told me IRL that the throttling could happen in gaia, but you suggest that throttling in Webapps.jsm could be a better solution (I happen to think the same, but it's more an instinctive thought). Fabrice, what do you think ?
Flags: needinfo?(fabrice)
We can do that in Webapps.jsm quite easily. patch coming.
Flags: needinfo?(fabrice)
(In reply to Julien Wajsberg [:julienw] from comment #25) > I was basically suggesting this in my bug report ;) I noticed it and I thought we came around full circle :) But it's always better to have hard numbers to back up a solution.(In reply to Fabrice Desré [:fabrice] from comment #26) (In reply to Fabrice Desré [:fabrice] from comment #26) > We can do that in Webapps.jsm quite easily. patch coming. I was cooking up one myself but I'll leave it to you then, my JS expertise is slim at best. However I can confirm that by applying a very crude throttling to the progress events the problem was essentially gone on my Otoro.
Assignee: gsvelto → fabrice
Attached patch patch (obsolete) — — Splinter Review
Attached patch patch v2 — — Splinter Review
I added support to also throttle the appcache progress events. I tested with owapps.cloudfoundry.com and everything looked alright.
Attachment #691437 - Attachment is obsolete: true
Attachment #691558 - Flags: review?(ferjmoreno)
Comment on attachment 691558 [details] [diff] [review] patch v2 Review of attachment 691558 [details] [diff] [review]: ----------------------------------------------------------------- r=me with the comment addressed, please. ::: dom/apps/src/Webapps.jsm @@ +1718,5 @@ > + if (now - lastProgressTime > MIN_PROGRESS_EVENT_DELAY) { > + self.broadcastMessage("Webapps:PackageEvent", > + { type: "progress", > + manifestURL: aApp.manifestURL, > + progress: aProgress, It seems that we can trust the |app.progress| here and remove the |progress| param from the message. We are assigning the same value in http://mxr.mozilla.org/mozilla-central/source/dom/apps/src/Webapps.js#519
Attachment #691558 - Flags: review?(ferjmoreno) → review+
(In reply to Fabrice Desré [:fabrice] from comment #29) > I added support to also throttle the appcache progress events. I tested with > owapps.cloudfoundry.com and everything looked alright. Tested on my Otoro too and it's looking good. Just my 2p on the patch: when I was trying to come up with a patch I was wondering if it would be possible to implement it using setInterval()/clearInterval() to poll the progress status at fixed intervals during the transfer; that would remove the call to Date.now() for every OnDataAvailable event. However due to my limited JS skills I couldn't come up with a working patch using this approach (nor do I know if it would actually be a better approach).
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Keywords: verifyme
QA Contact: jsmith
It's still not as fluid without a download and with a download (even if it's already better). Reopening and asking for :gsvelto to make some more measurement.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Flags: needinfo?(gsvelto)
renominating, this maybe could go to kilimandjaro.
blocking-basecamp: + → ?
(In reply to Julien Wajsberg [:julienw] from comment #35) > Reopening and asking for :gsvelto to make some more measurement. This is a 3s sample set when installing an app, taken with the notification tray pulled down and the spinner animation disabled by commenting out its 'animation' attribute in apps/homescreen/style/grid.css: http://people.mozilla.com/~bgirard/cleopatra/#report=f4b552b4bebb852b13da8c7f7944444ddc985924 Strangely enough there's lots of painting going on even though the progress bar is refreshed only once per second. Looking at the whole sample period reveals a number of calls to layout::DoReflow() involving app://system.gaiamobile.org/index.html: http://people.mozilla.com/~bgirard/cleopatra/#report=9b435be27d4b3210185a0df238be6b4bd6e651b8 This is weird as the progress bar is now refreshed only once per second which points to another periodic activity taking place and affecting the screen. I will try to figure out which element in the DOM tree is being touched and is causing the repainting to happen. On another note the time spent as a response to nsHttpChannel::OnDataAvailable is down to 16% and is mostly spent inside a write() call likely saving the file to the (slow) sdcard. So that part is now quite well behaved.
Assignee: fabrice → gsvelto
Flags: needinfo?(gsvelto)
we already landed patches against this bug. Can you please clone for follow up work. I don't think we'll run out of bug numbers :)
Status: REOPENED → RESOLVED
blocking-basecamp: ? → +
Closed: 13 years ago → 13 years ago
Resolution: --- → FIXED
Blocks: 822345
Status: RESOLVED → VERIFIED
Keywords: verifyme
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: