Search Unity

Increasing performance by lowering resolution...

Discussion in 'Scripting' started by astracat111, Mar 9, 2022.

  1. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    725
    I've done everything I can to improve performance including lowering shader quality, making sure shaders have only one pass, limiting alpha cutoff (for mobile), occlusion culling, limiting pixel lights, real-time shadows at low quality, etc etc...

    Recently when running on my older i3-1005g1 processor, I was able to get my game running at about 80+ fps at an experimental resolution of 480p/720x480, while in 720p/1280x720 it will probably run at 40-50fps. Plugged in that is, when it's on battery it chugs down to 20fps on more intensive parts...

    Now this is using the SetResolution() method....I have questions about resolutions and other platforms as well, for example porting to the Nintendo Switch or iPhone or Android. Will these platforms also work with the SetResolution() command, or for example is the Switch going to have it's own api once you get approved as a developer in where you can control screen resolution? For Android or iPhone, should I also be using a built in command of some sort to force the phone to run at a lower resolution?

    Also, on the Switch for example, does anyone know if 480p resolutions are supported? I'd assume it would be if it's running 3DS ports.

    For Windows, I would think you could rely on the win32 api to force screen resolution.
     
    Last edited: Mar 9, 2022
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,695
    Conspicuously absent from the above list is "attaching the profiler" and "instrumenting / measuring my code."

    Did you do that? If not, then you're just guessing and (potentially) wrecking your codebase for no gain whatsoever.

    DO NOT OPTIMIZE "JUST BECAUSE..." If you don't have a problem, DO NOT OPTIMIZE!

    If you DO have a problem, there is only ONE way to find out. Always start by using the profiler:

    Window -> Analysis -> Profiler

    Failure to use the profiler first means you're just guessing, making a mess of your code for no good reason.

    Not only that but performance on platform A will likely be completely different than platform B. Test on the platform(s) that you care about, and test to the extent that it is worth your effort, and no more.

    https://forum.unity.com/threads/is-...ng-square-roots-in-2021.1111063/#post-7148770

    Remember that optimized code is ALWAYS harder to work with and more brittle, making subsequent feature development difficult or impossible, or incurring massive technical debt on future development.

    Notes on optimizing UnityEngine.UI setups:

    https://forum.unity.com/threads/how...form-data-into-an-array.1134520/#post-7289413

    At a minimum you want to clearly understand what performance issues you are having:

    - running too slowly?
    - loading too slowly?
    - using too much runtime memory?
    - final bundle too large?
    - too much network traffic?
    - something else?

    If you are unable to engage the profiler, then your next solution is gross guessing changes, such as "reimport all textures as 32x32 tiny textures" or "replace some complex 3D objects with cubes/capsules" to try and figure out what is bogging you down.

    Each experiment you do may give you intel about what is causing the performance issue that you identified. More importantly let you eliminate candidates for optimization. For instance if you swap out your biggest textures with 32x32 stamps and you STILL have a problem, you may be able to eliminate textures as an issue and move onto something else.

    This sort of speculative optimization assumes you're properly using source control so it takes one click to revert to the way your project was before if there is no improvement, while carefully making notes about what you have tried and more importantly what results it has had.
     
  3. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    725
    @Kurt-Dekker I appreciate the help, and I'll try out the small texture idea, I've been doing things like that before in other areas as well, mainly shaders.

    It doesn't answer question of, since lowering resolution is speeding up the game, whether having a lower resolution would be solved by Screen.SetResolution or if I should be using the platforms app to do it.

    For example if I'm developing for the Switch, would Screen.SetResolution work with that, or could I expect there to be some sort of api function in where that would be set?

    This particular project doesn't need a higher resolution, since when optimizing it in this way it'd be on handheld screens.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,695
    I would have no idea... that's where you would run the profiler. It's obvious that changing that number does not change the raw number of pixels in the display that get updated.

    Nowadays there are many steps between your graphics being slammed to the first frame buffer, then getting shoveled through all the various scalers and filters for a given hardware display (including all the video drivers installed at that moment) and then actually making it onto the display hardware.

    And as you note, a lot of that stuff might have built-in power-saving firmware that reduces the pixel fill speed when running on battery... if it isn't documented, anything could be going on in the product team's pursuit of long battery life.
     
  5. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    725
    @Kurt-Dekker Interesting...

    It reminds me of the difference between when there were audio cards and now there's internal audio. You have internal audio not able to pull have low ms delay times compared with what are today usb audio interfaces that have seemed to replace audio pci cards like the soundblaster.

    Here's a question I have about Unity and platforms that you release on:



    So I have this resolution that works for this game I believe on handheld devices. This resolution works about 50% faster than 1280x720 pixels for this project.

    From what I understand, instead of using Screen.SetResolution() it would probably be better to use an API that comes with...the platform or is specific to that platform I think?

    Let's take an example...the Win32 API for windows and using ChangeDisplaySettings found here:

    ChangeDisplaySettingsA function (winuser.h) - Win32 apps | Microsoft Docs

    Also, about supported resolutions, is a device on Android for example or iOS simply not going to change the resolution with Unity's SetResolution() if it's not supported by the device? In that case, would I have to....maybe have the game displayed at 896x504 in this case, then basically expand it to the supported 720p (essentially down-scaling then stretching)? How would I stretch the game's viewport, or is this even possible?

    P.S - Another resolution I hear about is 852x480, apparently 480p, which is a 16:9 aspect ratio I believe, so stretching to 720p would probably fair better in this resolution, right? I'm getting good performance on the dual core uhd intel integrated graphics with this, it can't run 720p
     
    Last edited: Mar 9, 2022
  6. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    Just use SetResolution or ScalableBufferManager.ResizeBuffers.

    I assume with SetResolution devices will fallback to the nearest they can achieve. With dynamic resolution you can scale it to anything, because it's just some kind of render texture, but the performance boost isn't as good.
     
  7. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    725
    Gotcha...Interesting.

    I'm assuming that almost every device by default supports 1280x720. So, is it possible to have it display the game at 480p then resize it to fit 720p (just multiply the output resolution by 1.5)? Is that what 'ResizeBuffers' is?

    P.S - I found a good bit of information from this video:

     
    Last edited: Mar 10, 2022
    look001 and DungDajHjep like this.