PublisherAdview loadAds on background thread

174 views
Skip to first unread message

Ricardo Belchior

unread,
Jun 27, 2018, 8:35:39 AM6/27/18
to Google Mobile Ads SDK Developers
Hi,

I'm seeing a significant block of the UI thread when calling PublisherAdView.loadAd(). I understand from the documentation it performs the loading on a background thread but too much work seems to still be done on the UI. Here's some of my measurements for how long the method is running:
- loadAd() took 1767ms
- loadAd() took 115ms
- loadAd() took 67ms
- loadAd() took 49ms

Here's a few method traces I obtained with Debug.startMethodTracing/Debug.stopMethodTracing():

It always takes >1000ms on the first time the advert loads since app start, then it stays around 30-80ms. Which is still a considerable amount,  if one wants to reach the recommendation of 16ms per frame.
I've tried a suggestion from Vu Chao (https://groups.google.com/d/msg/google-admob-ads-sdk/91AxN2Q9Znk/kFa9Tq75BQAJ) to call MobileAds.initialize at Application#onCreate but I didn't notice any difference. 

Unfortunately when I try calling loadAd on a background thread, I get a runtime exception claiming setAdListener must be called on the main thread. Here's the stack trace:

Do you guys have any suggestion on how to improve the rendering of these ads? My code is pretty simple but let me know if you want to see the code.


Thank you,
Ricardo


Google Play services SDK version: 12.0.1 
Version of the Google Play services apk installed on device: 12.6.85
Device: Google Nexus 5X
Android Version: 8.1.0

mobileadssdk-a...@google.com

unread,
Jun 27, 2018, 3:38:30 PM6/27/18
to Ricardo Belchior, Google Mobile Ads SDK Developers
Hi Ricardo,

Can you try with our sample apps and let us know? Also send us your Ad Unit ID for us to look into this issue. You can use "Reply privately to Author" option to send the requested information.

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/7f572707-fa29-443c-ba94-d7c8309a247d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ricardo Belchior

unread,
Jun 28, 2018, 7:11:41 AM6/28/18
to Google Mobile Ads SDK Developers
Sure, I just sent (privately) a zipped file with the sample code and our ad unit id.

mobileadssdk-a...@google.com

unread,
Jun 28, 2018, 3:34:45 PM6/28/18
to Ricardo Belchior, Google Mobile Ads SDK Developers
Hi Ricardo,

Thank you for the sample app. You are not checking the AdResponse in your logs and instead looking at the AdRequest body itself. Can you log and check if the AdResponse is (onAdLoaded) is being fired quickly? The first AdRequest will always take an additional time to fire up and will reduce with subsequent AdRequest callbacks.

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.

Ricardo Belchior

unread,
Jun 29, 2018, 4:31:50 AM6/29/18
to Google Mobile Ads SDK Developers
Hi Deepika,

Thanks for having a look. Not sure this is what you suggested, but I added an adListener and tracked how long it took for #onAdLoaded to be triggered, see below.

But in fact, I don't mind that #onAdLoaded takes a long time. I also don't mind if the first AdRequest takes an additional time to do whatever it needs. I'm only concerned that it doesn't do that on a background thread! Otherwise there will always be a jank in the UI, am I right?

My request here is if it's possible for the PublisherAdView class to remove the restriction of #loadAds being triggered on the main thread -- it's actually some method down the line -- and internally if you guys need to post something on the UI thread call the View#post(() -> {...}) or equivalent. Because there's already a listener, we can be notified when to display the advert, I just want to be able to call it from any thread.



Here's the logs for opening and closing the activity, the first 3 times since app launch:
06-29 09:04:31.677 8312-8312/com.google.android.gms.example.bannerexample D/MyActivity: #onCreate: begin
06-29 09:04:32.748 8312-8312/com.google.android.gms.example.bannerexample I/MyActivity: loadAds took: 1055ms
06-29 09:04:32.749 8312-8312/com.google.android.gms.example.bannerexample D/MyActivity: #onCreate: end
06-29 09:04:37.171 8312-8312/com.google.android.gms.example.bannerexample I/MyActivity: onAdLoaded after 5491ms
---
06-29 09:04:51.748 8312-8312/com.google.android.gms.example.bannerexample D/MyActivity: #onCreate: begin
06-29 09:04:51.870 8312-8312/com.google.android.gms.example.bannerexample I/MyActivity: loadAds took: 120ms
06-29 09:04:51.870 8312-8312/com.google.android.gms.example.bannerexample D/MyActivity: #onCreate: end
06-29 09:04:54.225 8312-8312/com.google.android.gms.example.bannerexample I/MyActivity: onAdLoaded after 2474ms
---
06-29 09:05:04.593 8312-8312/com.google.android.gms.example.bannerexample D/MyActivity: #onCreate: begin
06-29 09:05:04.787 8312-8312/com.google.android.gms.example.bannerexample I/MyActivity: loadAds took: 192ms
06-29 09:05:04.789 8312-8312/com.google.android.gms.example.bannerexample D/MyActivity: #onCreate: end
06-29 09:05:07.298 8312-8312/com.google.android.gms.example.bannerexample I/MyActivity: onAdLoaded after 2703ms
---


Thanks for taking the time!

Cheers,
Ricardo

mobileadssdk-a...@google.com

unread,
Jun 29, 2018, 3:30:01 PM6/29/18
to Ricardo Belchior, Google Mobile Ads SDK Developers
Hi Ricardo,

Thanks for sharing additional details. I've shared this with the rest of the team and would like to investigate this further. I'll update you as soon as I get some additional information from the team.

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.
Message has been deleted

mobileadssdk-a...@google.com

unread,
Jul 2, 2018, 3:08:19 PM7/2/18
to Ricardo Belchior, Google Mobile Ads SDK Developers
Hi Ricardo,

Thanks for waiting. I had a discussion with the rest of the team and they confirmed that you have to call loadAds() from the main thread only with the current version of the SDK. This is on purpose and cannot be called from the background thread. 

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/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

On 06/29/18 16:12:40 ricard...@gmail.com wrote:
Awesome!! Thanks for digging into it!

--

---
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.

Ricardo Belchior

unread,
Jul 3, 2018, 12:01:47 PM7/3/18
to Google Mobile Ads SDK Developers
Hi,

That's unfortunate but thanks looking into it. Any plans to change that behavior in a future version?


Cheers,
Ricardo

mobileadssdk-a...@google.com

unread,
Jul 3, 2018, 3:17:36 PM7/3/18
to Ricardo Belchior, Google Mobile Ads SDK Developers
Hi Ricardo,

I'll share your concern with the rest of the team. You can always get latest updates on new changes in SDK through our blogpost.

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.
Reply all
Reply to author
Forward
0 new messages