New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 619812 link

Starred by 3 users

Issue metadata

Status: Archived
Owner:
Closed: Sep 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: Bug



Sign in to add a comment

Add memory test that involves multiple webviews (not just navigating a single webview)

Reported by howard....@mediatek.com, Jun 14 2016

Issue description

Steps to reproduce the problem:
1. install the app-debug.apk (this is a simple apk uses system webview)
2. attach adb, execute the script. This script uses adb shell command to fire an intent.action.VIEW with selected url, run the script for a period of time, 
3. During the test, dump smaps to observe PSS or RSS of this apk through adb

What is the expected behavior?
No obvious memory bloat in webview

What went wrong?
PSS memory with inode [anon:malloc] bloats in webview 
In attached test result, During 3.5 hour test period , webview is created/destroy 730 times, Memory increased from 30420KB ->47368KB , bloating about 4.72MB per hour.

Did this work before? No 

Chrome version: 51.0.2704.36   Channel: n/a
OS Version: N
Flash Version: N/A

WebView version (from system settings -> Apps -> Android System WebView): 51.0.2704.36 

This apk with a single task activity, which only maintain 1 webview.
when a new intent is arrived:
(1) detach & destroy current webview (if any)
(2) create a new webview and load the requested url.

The script fires an intent of following URLs in order, one at a time:
http://tw.yahoo.com/?m=1
http://www.mobile01.com/
http://taobao.com
http://sina.cn/?from=wap
http://www.amazon.com/
http://hao123.com
http://i.ifeng.com/
http://tmall.com
http://gmw.cn
http://www.gamer.com.tw/

[Attachment]
App-debug.apk  // test apk
test_script.bat   // test script
libc_malloc.html // test result
smaps.rar        // smaps log
 
app-debug.apk
1.1 MB Download
test_script.bat
2.7 KB View Download
libc_malloc.html
2.7 KB View Download
smaps.rar
4.5 MB Download
Components: Mobile>WebView

Comment 2 by torne@chromium.org, Jun 14 2016

Can you also attach the source for your test app?

Does it grow in the same way if you keep the same WebView instance and just navigate it repeatedly?

Comment 3 by torne@chromium.org, Jun 14 2016

Also, is that actually the same process (with the same pid) throughout the entire test? The maps for the first and last sample look very different (same read-only things mapped at different locations).

Comment 4 by torne@chromium.org, Jun 14 2016

Cc: perezju@chromium.org
Do any memory pressure signals get sent during this test? If there's lots of ram available and no memory trim signals are ever received, I think it's somewhat expected that various caches may get larger. Also, what device is this on? Have you tried this on different devices and seen a consistent pattern?

I asked perezju@ to look into the page cycler tests we run on our bots to see if we have a similar pattern of memory usage growing during the run; we don't currently run any tests for so long/so many cycles, though.
Attached source code of test app

#2:
Haven't tried with same webview instance yet. I'll see if this makes this issue better.

#3:
It should be the same process, otherwise i won't able to get the smaps (they were dump by a script, during the test)

#4:
This test was run on a nexus 6, I'm not sure if any memory pressure signals was sent during the test. I'll try again an see this happens.

Actually we found this pattern while testing our webview-based browser app(on  different devices). The malloc part keeps bloating even if we manually trigger the pressure signal.
app_src.zip
34.4 KB Download

Comment 6 by boliu@chromium.org, Jun 14 2016

yeah, there isn't enough evidence from the data that there is a leak, not everything can be cleaned up, and looking at the graph, it's not growing anymore in the second half

maybe use this bug to track adding memory testing across many webviews, not just one? perezju?
re #6: On our webview shell [1], would that just mean always navigating to pages through, e.g., the TelemetryActivity (as opposed to devtools)? Or do we need a new activity? Does it matter whether we close/restart the shell between pages?

[1]: https://cs.chromium.org/chromium/src/android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/

Comment 8 by torne@chromium.org, Jun 14 2016

I'd have to read the source for this test app first to check (haven't had time yet).

Comment 9 by boliu@chromium.org, Jun 14 2016

Not sure actually..

I don't know telemetry all that well, but I would guess it's navigating within the same tab, so in webview's case, in the same webview? Does it have concepts like "create a new tab", that kind of thing? If yes, maybe we can hook those for the webview shell as well, where a "tab" maps to a webview, and closing a tab maps to destroying a webview.

If not, maybe we can add a custom intent that 1) destroys the old webview, 2) create new webview and navigate to url from intent?

The existing system health memory test is just navigating a single webview.
Cc: timvolod...@chromium.org
+timvolodine to confirm what would be needed to test this scenario

Comment 11 by boliu@chromium.org, Jun 14 2016

Cc: nednguyen@chromium.org
I assume tim is going to give you the exact same answer. The shell isn't all that complicated :p

+nednguyen: Does telemetry have a concept of tabs in chrome? eg operations like open/close a tab, navigate a specific tab, that kind of thing?
Yes, Telemetry does have the concepts of opening/closing tabs, implemented for Chrome by sending commands via devtools: https://cs.chromium.org/chromium/src/third_party/catapult/telemetry/telemetry/internal/backends/chrome_inspector/devtools_client_backend.py?l=223
I actually though we already had something like this in tests.. Looking at the attached code it seems the test is performed by firing intents multiple times on a special activity which destroys/recreates the webview on each intent. We could also create a special activity and do something similar for tests. Or maybe just destroy/create webview multiple times within one activity depending on how memory telemetry is performed.

The concept of tabs is nice and we probably should consider implementing it, but for this specific issue does not seem to be really required.

Cc: primiano@chromium.org
I think adding a new activity that destroys/recreates the webview + navigates to a url given in the intent would be the way to go.

Tim, could you look at this and then assign back to me to create a new benchmark?
Owner: timvolod...@chromium.org
Status: Assigned (was: Unconfirmed)
ok will have a look

Comment 16 by boliu@chromium.org, Jun 15 2016

Summary: Add memory test that involves multiple webviews (not just navigating a single webview) (was: [Android Webview] Chromium Memory bloats when repeating creates / destroy webview)
Changing title
thanks Bo, title sounds better now..
Cc: petrcermak@chromium.org
Labels: -Pri-2 Pri-3
Owner: perezju@chromium.org
Assigning to self to write a benchmark using the new activity provided. Although probably will get back to it by the end of the quarter.

+Petr FYI, not sure how/whether this would fit as part of system health stories.
I think this probably fits into "App switching case" row in https://docs.google.com/spreadsheets/d/1t15Ya5ssYBeXAZhHm3RJqfwBRpgWsxoib8_kwQEHMwI/edit#gid=0 ?
Good question. I suppose it does make sense to include WebView stories in SH if we already plan to include AMP etc. However, I think that such stories will need to be in a separate story set and, probably, a separate benchmark because they require more "special" conditions.
Cc: -petrcermak@chromium.org
Cc: -petrcermak@chromium.org
From tobiasjs (context  issue 668692 ):

Running this about 20 times would generate a 1MB leak:
adb shell am start org.chromium.webview_shell/org.chromium.webview_shell.WebViewCreateDestroyActivity
n_threads=$(adb shell dumpsys meminfo org.chromium.webview_shell | grep TOTAL | head -1 | awk '{print $2}')
pss=$(adb shell cat /proc/$(adb shell ps | grep webview_shell | awk '{print $2}')/status | grep Thread | awk '{print $2}')
echo $n_threads $pss
Status: Archived (was: Assigned)
Archiving old issues which are likely no longer relevant and I probably won't work on them.

Reopen if you think an issue should be looked at again.

Sign in to add a comment