Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Unity 2022 - Extra Native memory allocation

Discussion in 'General Discussion' started by UDN_7c0cc375-4601-426b-9173-9b0d01d22807, Aug 11, 2023.

  1. UDN_7c0cc375-4601-426b-9173-9b0d01d22807

    UDN_7c0cc375-4601-426b-9173-9b0d01d22807

    Joined:
    Mar 21, 2014
    Posts:
    3
    Hi there

    We have updated Unity 2020 to Unity 2022 and we observed 100 mb increase in memory as per the Xcode profiler data.

    Unity 2022 has Extra Native memory allocation that is IL2cppMemoryAllocator takes 103 mb of memory which was not in 2020. Can you please help us how we can reduce 100 mb, so game would be playable in low end devices.

    Please find the attached screenshots for reference.

    Device Used for Profiling :
    OS iOS 14.7.1
    Device iPhone 7-23
    Chipset Apple A10 Fusion
    CPU Quad-core 2.34 GHZ
    GPU PowerVR Series7XT Plus
    RAM 2GB RAM

    Thanks
     
  2. UDN_7c0cc375-4601-426b-9173-9b0d01d22807

    UDN_7c0cc375-4601-426b-9173-9b0d01d22807

    Joined:
    Mar 21, 2014
    Posts:
    3
    Images attached for reference
     

    Attached Files:

  3. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,140
    Hi,
    In 2022 we've changed IL2CPP to use Unity's native Memory Manager and its allocation tracking system to make its allocations for the Virtual Machine memory (this includes allocations to hold stuff like e.g. Managed Type information and e.g. the use of Generics can have a huge impact on that amount), instead of making these allocations in a way that was previously "Untracked". I.e. that amount should not be what the increase you see in XCode is, but just a shift from the "Untracked" bucket into the "Native Memory" bucket. That said, newer versions of the package should show those 103 MB as "Virtual Machine (IL2CPP)" memory on the summary page.

    Which exact Unity versions did you capture from and in which version of the Memory Profiler Package did you open this in?
     
  4. UDN_7c0cc375-4601-426b-9173-9b0d01d22807

    UDN_7c0cc375-4601-426b-9173-9b0d01d22807

    Joined:
    Mar 21, 2014
    Posts:
    3
    We are using Unity 2022.3.4f1. The memory for this experiment is compared using the memory profiler "0.7.1-preview.1”.

    Please note our project was upgraded from Unity 2020.3.46f1 to Unity 2022.3.4f1.

    Note:

    During profiling the memory in Unity version 2022.3.4f1 with profiler 1.0.0 and 0.7.1-preview, the data shows significant differences.

    Please find this memory snapshot that uses same game profile. Managed heap, Native, and executables all differ greatly. Please guide us to fix this issue.

    Thanks
     

    Attached Files:

  5. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,140
    You can open both snapshots in 1.0, or even 1.1.0-pre.1, for more comparable data representation.
    You can import snapshot from older Unity versions into the 2022 project via the Memory Profiler's menu bar button for importing, or just copy the file into the same snapshot folder (that's what import does).
    You can also look at these two in comparison view and check the All Of Memory table.
     
    Last edited: Aug 18, 2023
    DragonCoder likes this.
  6. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,140
    That package version can't parse the IL2CPP VM Memory from the snapshot correctly, as it is reported differently than how the the Mono VM memory is reported and the 0.7.1 package version could not predict that. Consequently, it'll show that memory as native memory.

    This should not affect how memory is reported and tracked. That said, captures taken on 2020.x that are still in that capture folder or imported into it would have a different, potentially less accurate, basis for their data.

    In 2022.2 we closed most reporting gaps (i.e. memory allocated by Unity's systems should no longer be "Untracked") and the remaining "Untracked" amount is now no longer based on a single query to the OS to report the amount allocated by the app (which in some older versions was also not using quite the most accurate stat on all platforms). Instead it is based on going over all memory pages allocated by the app. This and fixes to the old query (which is still used for stats like the Memory Profiler Module's "System Used Memory" counter). We're quite confident that with that, we can at least confidently tell what we don't have concrete information on via our Memory Manager, where 2020 might still have been somewhat inaccurate or less precise, also depending on the platform.

    So the way the data gets reported changed with the Unity version the snapshot was taken from. The package version is irrelevant to the captured data, but the newer package versions are adjusted to parse and present the data in a way that is more consistent with the discoveries that led to the adjustment to the reported data. That, and then there are Bugfixes. So even if the snapshot file doesn't change, the newer package versions parse that same data in a way that is usually (unless affected by bugs) more accurate.

    In this case I think the IL2CPP VM Memory was:
    • Not present / Untracked in 2020
      • Plus Untracked was less accurate
    • Present in 2022 but parsed as Native memory in 0.7
    • Parsed as Managed Memory in the Summary in 1.0
      • Therefore NOT tracked as Native Memory
    Similarly, the Executables & DLLs has been made more accurate, both via reporting the data for them differently and by parsing it differently in the package.

    Long winded way of saying: try using the latest package version for comparing the snapshots and largely ignore what older package versions said. There's always the possibility of bugs but I'd base them on other observations, e.g. if stuff doesn't add up within a package version or conflict with native platform profilers.
     
    MadeFromPolygons likes this.