MediaEngagementService web contents observer creation takes 80ms during Chrome startup |
||||
Issue descriptionData from the UMA Sampling Profiler shows that creation of the MediaEngagementService web contents observer is taking a combined 80ms to execute during browser process pre-message loop startup, or 3.4% of the time required to start the message loop. This was observed in canary release 64.0.3282.0 on 64 bit Chrome on both Windows and Mac. This seems excessively expensive. From the profiles, almost all the execution time occurs in MediaEngagementService::GetEngagementScore(). This code appears to have gotten progressively slower over time -- from 1ms in 63.0.3203.0 to 80ms now. Profile of MediaEngagementService creations in 64.0.3282.0 canary on 64 bit Windows: https://uma.googleplex.com/p/chrome/callstacks?sid=511df9289f51cca0a14265e5c7ddc916
,
Dec 5 2017
,
Dec 14 2017
Windows' fault tolerant heap stack logging added another 40ms to the time taken for this code in 65.0.3292.0[1], so I took a deeper look into what's going on.
Most of the time taken is in content_settings::Rule creation and destruction, particularly the cloning and destruction of the of the base::Value iterating over each Rule. It looks like we're doing a ton of Rule creation and deletion.
The code is effectively implementing a double nested loop:
for each engagement origin:
for each content settings rule:
create a copy of the rule
check if the rule matches
destroy the rule
Presumably this has gotten progressively slower over time because the number of engagement origins has been continuously increasing as users do more browsing.
Can we either invert the loop ordering so that we're not creating and destroying each Rule for every origin, or avoid the Rule creation and destruction entirely? This probably should be done regardless of whether the execution gets moved to a background thread.
Looking at the numbers, the increase in execution time of this code is causing startup to regress by an additional *14ms per-week* on average. And the time is not uniformly distributed among users -- in 65.0.3292.0 canary the average execution time is now 125ms but users spend 300ms in this function at the 90th percentile and 2.1 seconds at the 99th percentile.
[1] https://uma.googleplex.com/p/chrome/callstacks?sid=592b1a6c02d58d8b5c5b54e195a4c93d
,
Dec 15 2017
Pending CL out to fix: https://chromium-review.googlesource.com/c/chromium/src/+/808484
,
Dec 18 2017
,
Dec 18 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/e505f9db8ab902f50b16368498198f8f74a8d13c commit e505f9db8ab902f50b16368498198f8f74a8d13c Author: Becca Hughes <beccahughes@chromium.org> Date: Mon Dec 18 14:29:44 2017 Media Engagement: Move record scores histo to task runner RecordStoredScoresToHistogram() is currently taking around 53.5ms when MediaEngagementService is constructed. This uses a task runner to record the scores asynchronously without blocking startup. BUG= 791779 Change-Id: I8302eea6ab50411471572edb0b12f78f2986f144 Reviewed-on: https://chromium-review.googlesource.com/808484 Commit-Queue: Becca Hughes <beccahughes@chromium.org> Reviewed-by: Mounir Lamouri <mlamouri@chromium.org> Cr-Commit-Position: refs/heads/master@{#524703} [modify] https://crrev.com/e505f9db8ab902f50b16368498198f8f74a8d13c/chrome/browser/media/media_engagement_score.cc [modify] https://crrev.com/e505f9db8ab902f50b16368498198f8f74a8d13c/chrome/browser/media/media_engagement_score.h [modify] https://crrev.com/e505f9db8ab902f50b16368498198f8f74a8d13c/chrome/browser/media/media_engagement_service.cc [modify] https://crrev.com/e505f9db8ab902f50b16368498198f8f74a8d13c/chrome/browser/media/media_engagement_service.h [modify] https://crrev.com/e505f9db8ab902f50b16368498198f8f74a8d13c/chrome/browser/media/media_engagement_service_unittest.cc
,
Dec 22 2017
Following up, we see a 102ms improvement in startup with this change: https://uma.googleplex.com/p/chrome/callstacks?sid=6fb0365e87b53e625597a32cccf777f3 ... which is most pronounced in message loop warm start: https://uma.googleplex.com/timeline_v2?sid=35b8f23359f988c461f63fa330dc9aed
,
Jan 5 2018
Bulk adding Performance-Browser label for bugs identified with the UMA Sampling Profiler. |
||||
►
Sign in to add a comment |
||||
Comment 1 by beccahughes@chromium.org
, Dec 5 2017