NativeAdView.setNativeAd is slow and blocking the main thread

1,318 views
Skip to first unread message

邱至民

unread,
Mar 9, 2018, 9:24:34 AM3/9/18
to Google Mobile Ads SDK Developers
I was found that the NativeAppInstallAdView.setNativeAd and NativeContentAdView.setNativeAd are very slow and blocking the main thread.
It took up to 50ms per call. It's impossible to have a smooth scrolling with this performance.

The only reason I choose to add NativeAd is to prevent the WebView bug which is crashing my app.
But I found this in the console.


There's no any BannerAd in this version of my app now. And I have no WebView in my app. But I still get some messages from WebView.
Are you still using WebView to load ads and handle impressions on NativeAds?
Even if I use the NativeAd, my app may still have this problem, https://groups.google.com/forum/#!topic/google-admob-ads-sdk/I6giN0VbVa0, in the future?
Is there a way to prevent the NativeAdView.setNativeAd blocking the main thread?

mobileadssdk-a...@google.com

unread,
Mar 9, 2018, 2:59:09 PM3/9/18
to 邱至民, Google Mobile Ads SDK Developers
Hi there,

The setNativeAd method must be run on the main thread since it's an UI task being performed. The Native Advanced AdView, under the hood, returns individual assets to be natively rendered by the app. This sounds like an implementation issue to me and I would suggest that you try with our sample apps and let us know if you are still able to reproduce.

Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/cc0b8e0d-b8f7-4fd9-9830-51d2df043ad9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

邱至民

unread,
Mar 10, 2018, 1:30:30 AM3/10/18
to Google Mobile Ads SDK Developers
Hi, 

Here's how I measured the execution time.

Stopwatch a4 = Stopwatch.createStarted();

adView.setNativeAd(contentAd);

Timber.d("a4 = " + a4.stop().toString()); // prints 30ms ~ 50ms

What kind of the implementation issue could make it take so much time on this one line codes?

mobileadssdk-a...@google.com於 2018年3月10日星期六 UTC+8上午3時59分09秒寫道:

邱至民

unread,
Mar 10, 2018, 2:01:35 AM3/10/18
to Google Mobile Ads SDK Developers
Hi, 

The execution time of the NativeAdvancedExample are:

03-10 14:51:53.289 20182-20182/com.google.example.gms.nativeadvancedexample I/MainActivity: setNativeAd takes 21.28 ms
03-10 14:51:59.368 20182-20182/com.google.example.gms.nativeadvancedexample I/MainActivity: setNativeAd takes 17.03 ms
03-10 14:53:32.950 20182-20182/com.google.example.gms.nativeadvancedexample I/MainActivity: setNativeAd takes 17.27 ms
03-10 14:53:35.958 20182-20182/com.google.example.gms.nativeadvancedexample I/MainActivity: setNativeAd takes 15.87 ms
03-10 14:53:38.374 20182-20182/com.google.example.gms.nativeadvancedexample I/MainActivity: setNativeAd takes 18.68 ms
03-10 14:53:40.957 20182-20182/com.google.example.gms.nativeadvancedexample I/MainActivity: setNativeAd takes 14.74 ms
03-10 14:53:43.631 20182-20182/com.google.example.gms.nativeadvancedexample I/MainActivity: setNativeAd takes 15.93 ms

03-10 15:00:19.926 24179-24179/com.google.example.gms.nativeadvancedexample I/MainActivity: setNativeAd takes 20.45 ms
03-10 15:00:29.347 24179-24179/com.google.example.gms.nativeadvancedexample I/MainActivity: setNativeAd takes 18.48 ms
03-10 15:00:32.922 24179-24179/com.google.example.gms.nativeadvancedexample I/MainActivity: setNativeAd takes 21.20 ms


Terrible performance. The test device is HTC D830x with Android 5.1.


mobileadssdk-a...@google.com於 2018年3月10日星期六 UTC+8上午3時59分09秒寫道:

mobileadssdk-a...@google.com

unread,
Mar 12, 2018, 3:25:16 PM3/12/18
to 邱至民, Google Mobile Ads SDK Developers
Hi there,

This depends on the device type and also on the type of creative being returned. A video creative might take longer compared to a static one. Can you test with a different device and see if the performance remains the same?

Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.

邱至民

unread,
Mar 13, 2018, 3:40:52 AM3/13/18
to Google Mobile Ads SDK Developers
Hi, 

I've tested it with my ongoing project, a test project and your NativeAdvancedExample on an emulator and a real device.
I don't think I have to waste more time to test it on another device again. It should be obvious that there's a problem inside your SDK.
If a video creative might take longer compared to a static one, then you should do these jobs in a worker thread. I mean, 25 ms is a crazy number.
And I didn't see any video when I did the test. I think those debug messages are from static ads. 
So the video ads might take longer than 25 ms?

This issue is still not resolved after 9 months.

This issue is still not resolved after 6 months.

This issue is still not resolved after 4 months. And you're preparing to release API 28.

There are more than that.
Looks like you're not concerning about those bugs anymore.
The adLoader.loadAd and the nativeAdView.setNativeAd are doing too much work in the main thread.
And you should change your way to detect whether the adView is visible rather than check all the view hierarchies on the screen.
Using WebView is a bad idea too. You should use a web service and custom views for these ads.
It would be appreciate if you can take these problems seriously.

Thanks.

mobileadssdk-a...@google.com於 2018年3月13日星期二 UTC+8上午3時25分16秒寫道:

mobileadssdk-a...@google.com

unread,
Mar 13, 2018, 6:46:38 PM3/13/18
to 邱至民, Google Mobile Ads SDK Developers
Hi,

Thanks for your feedback. We acknowledge your concerns around performance of the 'setNativeAd' call and I've filed an issue internally to inspect this and look for optimizations.

The call is primarily doing a lot of UI thread work that involved native view tracking and manipulation, but we will look for bottlenecks and ways to improve the performance.

With regards to your concerns around web views, we do use webviews as part of the native ads solution, but the webviews are not used for loading creative content, which we believe is the primary cause of the SIGTRAP crashes that you referred to. The webview and JS logs you provided are related to view tracking and internal implementations, these calls are well tested and immutable and should not cause any webview crashes.

With respect to the webview crashes you referred to, unfortunately if we cannot identify a case that reproduces a crash it is hard to resolve. It seems apparent that some creatives JS is causing webviews to crash, and these crashes are not able to be caught by the AdMob SDK and hence cause the app to crash. This is definitely unfortunate and undesirable, but we do not have a solution for this as part of the AdMob SDK.

We will update you if any performance improvement opportunities are identified that may help resolve this issue for you.

Regards

Sam


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~


mobileadssdk-a...@google.com於 2018年3月13日星期二 UTC+8上午3時25分16秒寫道:

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.

鲁晓宇

unread,
Mar 14, 2018, 6:47:35 AM3/14/18
to Google Mobile Ads SDK Developers
I met the same problem that setNativeAd cost 50ms...

03-13 21:23:32.806 19846 19846 I TimeLogger: [getNextAd1] costs 51


在 2018年3月9日星期五 UTC+8下午10:24:34,邱至民写道:

mobileadssdk-a...@google.com

unread,
Mar 14, 2018, 12:24:25 PM3/14/18
to 鲁晓宇, Google Mobile Ads SDK Developers

Thanks, yes we are aware of the issue and are tracking it internally, we will update with findings as they happen.

Regards

Sam

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.

Mieszko Stelmach

unread,
Dec 4, 2018, 3:40:42 AM12/4/18
to google-adm...@googlegroups.com
Do you have any update about this bug?
We also have the same issue with loading native ads. Scrolling is lagging when there are native ads.
There are also crashes related to webview in ads (we have only native ads and no webview based ones).

Fran Soto

unread,
Mar 28, 2019, 8:21:31 AM3/28/19
to Google Mobile Ads SDK Developers
A year without updates....

邱至民

unread,
Jun 28, 2019, 3:42:59 AM6/28/19
to Google Mobile Ads SDK Developers
Happy Anniversary!!!
Looks like you are terrible on performance tuning.
Or you guys just want to fix it by hardware?

Fran Soto於 2019年3月28日星期四 UTC+8下午8時21分31秒寫道:
Reply all
Reply to author
Forward
0 new messages