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

Minimizing RAM or CPU usage?

Discussion in 'General Discussion' started by swyrazik, Mar 6, 2015.

  1. swyrazik

    swyrazik

    Joined:
    Apr 21, 2013
    Posts:
    50
    I was thinking how to implement something and I had 2 methods: 1 which would be more CPU intensive but use less memory, and 1 which would be more memory expensive but less CPU intensive. In the end I chose the second one because I liked it more, but at this point it doesn't really matter. If I tried to see which is the better method in terms of performance, it would be premature optimization.

    So I was wondering if developers generally tend to minimize RAM or CPU usage. In other words, can we usually afford higher RAM usage or higher CPU usage?
     
  2. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,033
    On a desktop system you usually have plenty of RAM, so I'd go for that first. You can afford hundreds of megabytes on caches. On mobile devices both CPU and RAM increase approximately in sync, except for weird, cheap devices, so it's a little trickier to choose.
     
  3. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    In general, I would say "it depends" and that you should ideally try to balance out using the CPU and RAM without leaning too heavily on one or the other. But Unity is a special case, in that its garbage collector sucks, and too many allocations will actually stall out the CPU and affect framerate, so trying to avoid CPU by using RAM might actually backfire and just cause you to lose memory AND cpu. Using single large block allocations of memory is ok, but using lots of small object allocations that have to be garbage collected is the worst of both worlds.
     
  4. knr_

    knr_

    Joined:
    Nov 17, 2012
    Posts:
    258
    What platforms are you targeting, what are each of their CPU specs & RAM specs (aside from PC / Mac desktop which can vary)?
     
  5. ChipMan

    ChipMan

    Joined:
    Mar 4, 2015
    Posts:
    122
    Cut down on the amount if Update() calls every frame :)
     
  6. swyrazik

    swyrazik

    Joined:
    Apr 21, 2013
    Posts:
    50
    Thanks for the info, everyone :)

    I'm currently targeting desktop, but there's a possibility that I target Android/iOS (where there's also a variety of specs) later on.
     
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    The profiler is available in free now!

    Profile on your target device, and see what happens.
     
  8. ChipMan

    ChipMan

    Joined:
    Mar 4, 2015
    Posts:
    122
    Noooooooo why unity! Why do you give to Profiler FREE! :O
     
  9. swyrazik

    swyrazik

    Joined:
    Apr 21, 2013
    Posts:
    50
    Unity, why you so good? :(
     
  10. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    It's not that expensive to get a laptop with 16GB of RAM so I'm sure it's even more affordable on desktop. Mobile devices earlier this year had 2GB of RAM. It's a big gap but, but consider dying light started at like 10GB memory minimum but is now down to 4GB memory. You can always optimize later :D
     
  11. swyrazik

    swyrazik

    Joined:
    Apr 21, 2013
    Posts:
    50
    Yeah, I'm in no need of optimizing yet. So I understand that we can afford more RAM than CPU processing capacity.
     
  12. cl9-2

    cl9-2

    Joined:
    May 31, 2013
    Posts:
    417
    Is it a process that you can move to the cloud (i.e. VPS)? Perhaps save both CPU cycles and RAM?