How can I avoid Depsgraph rebuild times?

Not sure if here is the correct place to ask a question. I also posted the question here

I have two objects (in collections) in the scene and I want to render only one of them programmatically (from Python). When I measure the rendering time, there is always overhead of Depsgraph build time.

import time
import bpy

bpy.app.debug_depsgraph_time = True

start = time.time()
print("Start: ",start, "s")

bpy.data.collections['B747'].hide_render=False
bpy.data.collections['B757'].hide_render=True
bpy.ops.render.render(animation=True)

end = time.time()
print("End: ", end, "s")
print("Duration: ",end -start)
Start:  1687435725.4579306 s
Depsgraph built in 0.105444 seconds.
Depsgraph updated in 0.009703 seconds.
Depsgraph evaluation FPS: 0.020573
Saved: '/tmp/output0001.exr'
 Time: 00:00.14 (Saving: 00:00.02)

Depsgraph updated in 0.008152 seconds.
Depsgraph evaluation FPS: 0.023989
End:  1687435725.734076 s
Duration:  0.27614545822143555

As you can see, rendering + saving takes only 0.14 seconds while the whole duration of the code is 0.27 seconds.

When I comment out hide_render, there is no such overhead.

# bpy.data.collections['B747'].hide_render=False
# bpy.data.collections['B757'].hide_render=True
Start:  1687435918.4967954 s
Depsgraph built in 0.000358 seconds.
Depsgraph updated in 0.001326 seconds.
Depsgraph evaluation FPS: -nan
Saved: '/tmp/output0001.exr'
 Time: 00:00.16 (Saving: 00:00.02)

Depsgraph updated in 0.008340 seconds.
Depsgraph evaluation FPS: 0.020629
End:  1687435918.680713 s
Duration:  0.18391752243041992

Here, we observe 0.02s overhead which is fine.

Now, I want to avoid this Depsgraph build time overhead due to hide_render.

What I tried is:

  1. Move away method
    • Leave all the objects to be rendered and do not configure hide_render in the code.
    • Move the object away from the camera that I do not want to render in the image.

=> It still loads the textures of all the objects for each rendering, so the rendering takes more time.

  1. Visibility method
    • Don’t touch hide_render.
    • Turn off all the visibility parameters to False e.g. visible_camera, and so on

=> Same as 1.

Is there a way that I do not reload all the objects per rendering without setting hide_render?

1 Like

If you’re using Cycles to render your scene then there’s an option called Persistent Data in the Performance panel of Cycles settings. This will keep as much information as possible in RAM/VRAM between each subsequent renders (E.G. It keeps textures in memory).

This means you can use method 1 or 2 (move objects away from where you’re rendering, or turn off all visibility settings) and not have to deal with reloading textures.

However, if you’re using EEVEE or Workbench and want to switch to Cycles to take advantage of this feature, then you may notice it’s slower due to the added Cycles initialization time.

Hi @Alaska , thanks for the answer.

I am currently using Cycles and I do set Persistent Data on.

Even rendering the same scene without changing anything, I still see these logs that it’s loading the texture images:

Fra:1 Mem:588.43M (Peak 615.20M) | Time:00:00.00 | Mem:0.00M, Peak:0.00M | Scene, View Layer | Synchronizing object | aa1
Fra:1 Mem:590.61M (Peak 615.20M) | Time:00:00.01 | Mem:0.00M, Peak:0.00M | Scene, View Layer | Initializing
Fra:1 Mem:590.60M (Peak 615.20M) | Time:00:00.01 | Mem:0.00M, Peak:0.00M | Scene, View Layer | Updating Images | Loading panel.png.004
Fra:1 Mem:590.60M (Peak 615.20M) | Time:00:00.01 | Mem:0.00M, Peak:0.00M | Scene, View Layer | Updating Images | Loading seat.png
Fra:1 Mem:590.61M (Peak 615.20M) | Time:00:00.01 | Mem:0.00M, Peak:0.00M | Scene, View Layer | Updating Images | Loading interior.png.004
Fra:1 Mem:591.05M (Peak 615.20M) | Time:00:00.01 | Mem:0.00M, Peak:0.00M | Scene, View Layer | Updating Images | Loading vor.png
Fra:1 Mem:596.55M (Peak 615.20M) | Time:00:00.01 | Mem:0.00M, Peak:0.00M | Scene, View Layer | Updating Images | Loading kap140.png
Fra:1 Mem:618.93M (Peak 619.43M) | Time:00:00.03 | Mem:0.25M, Peak:0.25M | Scene, View Layer | Updating Images | Loading adf01.png
Fra:1 Mem:617.91M (Peak 619.43M) | Time:00:00.03 | Mem:0.75M, Peak:0.75M | Scene, View Layer | Updating Images | Loading alt.png.003
Fra:1 Mem:617.51M (Peak 619.43M) | Time:00:00.03 | Mem:1.00M, Peak:1.00M | Scene, View Layer | Updating Images | Loading turn.png.004
Fra:1 Mem:618.85M (Peak 619.43M) | Time:00:00.03 | Mem:1.25M, Peak:1.25M | Scene, View Layer | Updating Images | Loading asi.png.004
Fra:1 Mem:618.71M (Peak 619.43M) | Time:00:00.03 | Mem:1.31M, Peak:1.31M | Scene, View Layer | Updating Images | Loading ai.png.002
Fra:1 Mem:602.75M (Peak 619.95M) | Time:00:00.04 | Mem:12.13M, Peak:12.13M | Scene, View Layer | Waiting for render to start

I would like to know how I can skip this loading essentially.