Search Unity

Is there a way to force Unity Editor to use fewer threads?

Discussion in 'General Discussion' started by carrotstien, Feb 22, 2021.

  1. carrotstien

    carrotstien

    Joined:
    Jun 8, 2016
    Posts:
    37
    Whenever I build, including right now, I see all 8 cores ramp up to 100% cpu usage. Often i'm running mulitple processes, or even multiple editors on my machine. I'd love, for example, to say: hey this instance of unity, use cores 1-4, but don't touch the rest. This other instance, use 5,6. So 7-8 is for everything else like windows.

    At the very least, it'd be nice if I can force Unity editor to use only a single core. Sometimes I'm not in a hurry to build, but I don't want that time to make my computer less convenient to use.
     
  2. BennyTan

    BennyTan

    Joined:
    Jan 23, 2014
    Posts:
    141
    You can try using your task manager to limit the cores directly for the process.
    Task Manager -> Details Tab -> Right Click on desired process -> Set Affinity
     
  3. carrotstien

    carrotstien

    Joined:
    Jun 8, 2016
    Posts:
    37
    The problem is that as far as I understand, that sets the affinity of unity.exe ...but during the build, unity spawns a bunch of compiler process that run on other cores :(
     
  4. spacefrog

    spacefrog

    Joined:
    Jun 14, 2009
    Posts:
    734
    if you set the process priority of the running unity.exe process to low, all unity spawned processes will inherit that low priority setting. This should help a lot and shouldnt affect the other use of your computer while building

    Note: sometimes eg. for atlas baking or mobile texture import/processing low prio on the main unity process still causes totally sluggish general windows behavior, despite my 6/12 core machine. I guess this is mainly when the texture compressor uses some GPU acceleration
    Thats the only case i ever do the affinity trick to keep one core explicitely away from unity
     
  5. carrotstien

    carrotstien

    Joined:
    Jun 8, 2016
    Posts:
    37
    thanks, i'll try and report back
     
  6. carrotstien

    carrotstien

    Joined:
    Jun 8, 2016
    Posts:
    37
    hmm, that didn't seem to work...or maybe the reason cpus are all being used up has to do with some lower level stuff
    anyway, i set it to use 1 cpu, and once i started building, it looked like all cores shot up to 100%
     
  7. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    Setting affinity didn't work?
    Try also set low priority.

    Also, remember that because you use less of CPU, your drive may be busy reading and writing. So doing something else, while project is building for example, may be affected by that too, or vice versa.
     
    Joe-Censored likes this.
  8. BennyTan

    BennyTan

    Joined:
    Jan 23, 2014
    Posts:
    141
    Try starting the application with the desired affinity from the cmd prompt instead.

    Code (CSharp):
    1. start /affinity 1 C:\"Program Files"\Unity\Hub\Editor\2020.2.5f1\Editor\Unity.exe
    This will start unity, only using the first core. This applies to all spawned processes as well. Please note that the cores are labeled with 2^n where n is the core ID starting from 0, and the affinity argument is the sum of the core labels in Hex.

    For example,
    To make use of only the 3rd and 5th cores in your cpu
    You would first calculate the required value as 2^2 + 2^4 = 4 + 16 = 20
    Convert this to hex (base 16) which is 14
    and use 14 as the argument for affinity
    Code (CSharp):
    1. start /affinity 14 C:\"Program Files"\Unity\Hub\Editor\2020.2.5f1\Editor\Unity.exe
    You can then set up batch files for unity.exe based your affinity and unity requirements for your convenience.

    Unity Argument Reference:
    https://docs.unity3d.com/Manual/CommandLineArguments.html
     
    Last edited: Feb 26, 2021
  9. spacefrog

    spacefrog

    Joined:
    Jun 14, 2009
    Posts:
    734
    Of course it shoots up to 100% CPU usage - and thats a good thing. Running on low priority and using 100% cpu does not necessarily mean your input or other processes running on normal priority suffer lag or starving on cpu time...
    Usually you shouldnt care wether your cpu total is at 100% or not while running some serious tasks like building as long as it runs that on low priority, the OS is responsible giving all your other tasks priority
    But of course, if you still suffer from that , affinity mask would do the trick
     
  10. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I was reading this thread wondering if the problem isn't CPU, but maxing out access to the disk, causing other applications waiting on the disk to appear unresponsive. The problem can be made worse if you're maxing out your RAM at the same time, resulting in a lot of hitting the page file on the same maxed out drive.
     
    angrypenguin likes this.
  11. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    My pretty decent desktop (i7/32GB/SSDs/1080GTX) seems unable to browse the web while Unity 2020 is baking lighting or compiling shaders.

    I'm sure older versions weren't this bad. Unless there's something else on my machine that's only recently started causing a problem. (Sometimes task manager shows 'system interrupts' taking up loads of CPU time)

    I can happily browse away while baking with Bakery, though.
     
  12. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    2,198
    I have switched to PLM GPU baking now, but when I used PLM CPU I didn't notice these slowdowns. Actually the computer happily let me surf and do other stuff while all 32 threads were working 100 procent. The windows scheduler makes this happen.
     
  13. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,157
    I've had absolutely none of these problems doing the same on my less powerful (Ryzen 3600, 1070) computer with otherwise equal specs. I'm thinking there must be more at play here.
     
    BennyTan and Ryiah like this.