Optimizing URP renderer scripts

I’m working on optimizing my game, it currently can only run at 30 fps. The game is supposed to run at 60 fps. I’ve managed to optimize the some of my game scripts update functions to keep it stable, but this is the best I can get. Can someone see from this image if there’s something else I can optimize.

These are my recordings from the profiler.

If vsync is not on, dive into GPU profiling (render doc and NSight are great), the frame debugger to reduce draw calls, and other GPU optimizations

We can’t optimize images. :wink:

We could however provide optimization tips for code .. provided we would have some code to look at. (hint, hint) :thinking:

You can also do the same by the way, in case you’ve only been looking at the Timeline view. Change this to Hierarchy (or similar) so you can see the call tree, ordered by “time spent” which helps you quickly narrow down where most of the time is spent:

If that info is too coarse or doesn’t show enough details, enable Deep Profiling.

In case you have lots of GameObjects running essentially the same script, a common optimization is to refactor this into a single script doing the same thing for all objects - a single tight loop executes a lot faster than a thousand separate calls to Update.

I created a development build to test it, and it worked at 60 FPS without the editor loop, although it had a few garbage spikes. However, my computer is an AMD CPU, so I’m not sure about performance on Intel systems.

To be precise: you cannot be sure about the performance of your game on any other system other than the ones you test it on. Every system is unique.

In any case it won’t make a difference when comparing equivalent CPU models. Measurable differences perhaps, but not noticable.

However, unless you have a super high-end system or you declare your current system as the “recommended specs” your game still has a performance issue if it barely meets the 60 fps barrier. Since there will be users with lower specs, or with higher refresh rates expecting the game to run smooth at 240 fps.

If you compare your game to other games, would you expect it to run at more than 60 fps on your computer? If so, you have to spend some more time optimizing. And given that scripting is taking so much time I’d say there’s ample opportunity to change a few low-hanging fruits and get it to run at 120+ fps.

Feel free to share any hot code paths you determine with the profiler but don’t know how to improve.

I Tested out the deep profiler, and the render pipeline is where the largest CPU time is. Also my game uses large environments and many objects use LOD.


Okay if it’s rendering that takes most of the time there’s also things you can do but it probably doesn’t involve changing scripts. First check the GPU profiling stats to identify what part might be taking a long time to render, respectively to prepare on the CPU side.

This URP ebook has performance tips you can try:

If you have lots of individual objects you’ll want to flag all of those as “static” which never move, rotate or scale. And the GPU resident drawer can speed up rendering many individual objects. Alternatively, and best for performance if done right, is to bake multiple meshes into a single static mesh.

In the game view, enable the stats display (top right, in the toolbar). This gives you a rough assessment over whether time is spent on CPU vs GPU, and how many draw calls / batches are rendered. Reducing draw calls / batches isn’t nearly as important for desktop games but they too have a limit.

This is what I got from the GPU Usage. Buildings are made using modular prefabs.

I applied a static mesh bake to the environment and it did successfully reduce GPU load, but the shadow/depth is now taking over.

I’ve managed to reduce the Shadow rendering down by applying mixed light maps to the environment. I also applied more reforms to the scripts to reduce the load. It now runs at 30 fps when recording with profiler, 50 fps in editor without profiler and a stable 60 fps in a development build, which is normal because I limited it to 60 in script. I’m still not confident it’s resolved, and will continue testing on other computers.

I’ve performed one more test, this time not in deep profiler mode, and it ran at a smooth 60 fps, even in profiler mode. So basically, I just needed to bake my environment prefabs into a single mesh renderer to reduce draw calls and then bake a light map over it and have the directional light set to mixed. So I’m satisfied with the results.