Search Unity

Performance issues appearing after several ad displays.

Discussion in 'Unity Ads & User Acquisition' started by Starbox, Feb 22, 2021.

  1. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    This could be of interest to anyone who encounters such a problem, where one's game lags, becomes slow, might stutter or even freeze for several frames or seconds, or worse, crash, all that when ads are loaded and even oftener when they have been displayed when returning to the app. The problems start to occur.

    Beware, we're not talking about a loss of performance due to the downloading of ads. This could be expected although avoided if the loading is slated to happen in relatively quiet phases of one's game.
    What we're dealing with here is a performance issue that appears after a given number of repeated viewings (took me a few displays to encounter them but some people seem to report problems very early in using ads through their app).

    I don't use banners, only interstitial and rewarded ads and thus far are only limiting my tests to Unity, but such issues were also encountered with other providers and banner types.
    I'm only running test ads by the way so it should always be playing the same ad (in theory), or even if it re-downloaded the same test ad, it would logically replace the former one (who would want ad clones after all?). Could that cause a leak though?

    On internet, opinions are inversely proportionally varied as solutions are scarse. It doesn't seem to be strictly limited to Unity Ads as in several cases Admod Ads (Google) were involved too. It's also an old problem. I found this starting back in 2014 and appears to be an Android issue (mostly because of the variety of devices) although I read about a few people complaining on encountering these issues on iOS too.
    Here are some useful quotations to understand what might be going on.



    https://groups.google.com/g/google-admob-ads-sdk/c/ZYYJvEY_OTQ?pli=1
    The idea being that unloading a scene would dump the data but I doubt it.



    https://groups.google.com/g/google-admob-ads-sdk/c/IoPXkCOA-NQ


    https://answers.unity.com/questions/1089616/game-lagging-after-showing-unity-ads.html


    https://forum.unity.com/threads/performance-gets-worse-after-a-while-of-playing.844921/
    I'm using Unity Ads. My problem is that after playing several ads, one of them will suddenly make the game freeze during several seconds on the Samsung A5 I test on. The problem was so bad that even if the ad was validated, it made the code jump some functions (I heard validation noises such as for rewards) and the UI wouldn't update because of that freeze although the reward was delivered to the player.

    It would seem memory gets saturated. Now, that happens with Unity TEST ads but typically there is going to be a whole catalog of advertisements being rolled through one's device. I rely on a plugin and custom placements.



    https://forum.unity.com/threads/framerate-drops-after-unity-ad-runs-android.426008/
    This is exactly how I can solve this too. Just phasing out of and into the app solves this.
    Note that I coded a way to run a big GC when such events occur. So is this a purely media memory management issue? One that can be handled internally through Unity's GC?

    It's the second one.

    A "solution" was provided by adding an API level related line in the AndroidManifest.xml file but I don't see how it relates to the issue. I think the user got lucky with this one.



    https://www.g2.com/products/unity-ads/reviews#survey-response-425206


    https://www.reddit.com/r/PocketPlan...eal_tho_whats_with_the_unity_ads_that_freeze/
    Sure.



    https://www.reddit.com/r/androiddev/comments/ktzr6h/admob_and_unity_ads_tank_framerate_but_the/

    All seems to point to an excessive use of memory.
    In several cases, leaving the app (standby'd) and returning to it does solve the issue as if some pressure was building up and Unity just needed to have a break, get a smoke and then get back to work.
    There seems to be a solution that could be found by using Unity to do something in particular that would make the player think the app has been background'd.

    I for one am just going to force a big memory heap dump through the garbage collector but I do not know how ads are stored at all so this strategy is extremely speculative.
    Is it going to purge the memory of the ad(s), or is it going to purge something created alongside the ad by Unity, some kind of intermediary data, that just lingers there and keeps looking for something, a process that is bound to consume an insane amount of CPU the very moment memory has been all eaten up?

    I already looked into several plugins and have not seen functions to destroy/dump an interstitial or rewarded advertisement by force.
    I'm not even sure fiddling with the memory through the app would have any effect on this media storage, so I'm really thinking that Unity creates some intermediary agent or wrapping thingy that just begs to turn into an app-ruining monster if not enough memory remains to be sacrificed.
     
    Last edited: Feb 27, 2021
  2. alipaknahad

    alipaknahad

    Joined:
    Dec 22, 2020
    Posts:
    11
    Hi @Starbox, thank you so much for such unbelievably useful research. We are encountering the same problems (real bad lags and fps drop) on our android unity game.

    Seems like so far you are still struggling with the issue. But at some point you stated the problem is - Garbage collection on Android which I cannot find a solution to avoid this problem.

    Again, thanks a lot.
     
  3. Scalisco

    Scalisco

    Joined:
    Feb 2, 2014
    Posts:
    20
    I'd hate to bring up an old thread, but this is a problem for me, and there's not really a resolution in this thread yet.

    Has anyone found a reliable way of dealing with lag caused by ads? I am using Admob and notice that games get laggy on older devices (both Android and iOS) when the game is connected to the internet and ads are loading. Go Offline and the games run smoothly.
     
  4. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    Thus far, if I am correct, Unity seems to have no less than three advertising systems (don't quote me on that).
    • Advertisement Legacy: simply called Unity Ads back then.
    • Advertisement with Mediation: a rather very short lived suite since the IronSource merger.
    • (IronSource's) LevelPlay: consequence of the merger, the all new squeaky and shiny ads tools suite.
    Which one are you using?
     
  5. Heero888

    Heero888

    Joined:
    Jun 18, 2017
    Posts:
    57
    I have the same issue. Watching Applovin rewarded ads will trigger low memory warning.