Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Seems that Unity is allocation in a background thread

Discussion in 'General Discussion' started by Max-om, Nov 25, 2022.

  1. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    499
    Anyone heard anything about this? This is profiled with a built player

    upload_2022-11-25_17-39-47.png
     

    Attached Files:

  2. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,677
    Are you talking about those red spikes?
    Please provide more information.

    It's not surprising however to see some memory acquisition in the background even if your project is not acquiring any memory at the very moment.
    Since C# is a managed language it tries to maintain a buffer so not every request of your code for memory, has to go all the way to the OS (which is the slowest way to acquire memory).
    Also you will see a CPU spike in the background as well at times due to the garbage collector.

    Don't worry about it as long as it remains in the background thread.
     
  3. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    499
    You can see in the hirarchiy what code is allocating, some kind of file system watcher.

    It doesn't matter if the allocation is happening in the background the collection will halt the entire app domain
     
    angrypenguin likes this.
  4. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    499
    It would be great if unity could shed some light on this allocation because I can't find anything relevant when I google
     
  5. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    499
    Hey unity im getting crazy trying what his background thread is that allocates like crazy

    upload_2022-12-17_17-18-8.png


    Can you please shed some light?

    This is a built player with a stand alone profiler.
     
  6. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,085
    Select raw hierarchy, make deep profile build, select deep profile in profiler and unroll whole call stack. I wouldn't be surprised if it's a standalone profiler thread.
     
  7. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    499
    Thanks, but the raw one doesnt seem to output it different than the none raw one

    upload_2022-12-17_21-57-18.png
     
  8. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,085
    Unroll DefaultWatcher. Is it the same with editor profiler? What about empty project?
     
  9. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    499
    It's not there for a empty project it seems to be connected to XR plugin. Or possibly SteamVR but the steamvr code is open source and I can't find any DefaultWatcher code there. These is also no clues deeper down like a call to my code or SteamVR or any other code other than generic framework code
     
  10. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    499
    There is no clues who is the owner of the thread :/

    upload_2022-12-19_11-53-17.png
     
  11. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    499
    I tried recording GC.GetTotalMemory(false) and then log it at application exit and it could not detect any allocation (Built player)
     
    Last edited: Dec 19, 2022
  12. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    Well if you are only recording this at exit, then ofcourse GC will likely have cleared itself by then.

    Without explaining exactly how you are recording it and showing code, its really hard to point out what the problem likely is, both for us and for Unity engineers.
     
  13. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    499
    I was wrong above: I recorded from update loop it was to seldom. I instead recorded from a background thread. Now it detects allocation. Which means its not profiler polluting the result
     
  14. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    499
    I recorded during run and logged at application exit, What do you take me for? (Logging allocates)
     
  15. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    Well your previous comment alone shows exactly why I was asking how and what you logged, as clearly it was the culprit. So no need to get arsey mate, no point coming on a technical forum if you dont want to get asked about how and what you are doing ;)

    Either way glad you figured out what was giving you an erroneous output :)
     
  16. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    499
    I found the culprit, package com.valvesoftware.unity.openvr uses a System.IO.FileSystemWatcher in OpenVRLoader.cs
    It wasnt visible from my code since they reside in another sln

    I really dont know if we should blame package creator here or that Unity mono allocates in filewatcher
     
  17. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,965
    While looking into this I had a feeling it might be related to something involving VR. You may want to start saying as much in your posts because most people aren't going to think to look there let alone remember you're developing for it.
     
    MadeFromPolygons and lmbarns like this.
  18. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    400
  19. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    499
  20. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    Granted, it is rather unstable but just for the record: Standalone Profiler is a pure Editor concept. None of it's code lands in or affects the Player.