By default, TDW is optimized to strike a balance between simulation speed and realistic imagery and physics. This document explains how to optimize TDW for speed.
Before troubleshooting why your simulation is running slowly, we recommend comparing it to TDW's performance benchmarks.
If your controller is running significantly slower than our benchmark controllers, your code might not be optimized.
You should run TDW on a high-end machine. A powerful GPU is the single most decisive factor in overall performance.
Image capture is by far the slowest process in TDW.
If you don't need image data, don't request it! For example, requesting image data on every frame is much slower than requesting image data every 10 frames. Likewise, never request capture passes that you don't actually need. For example, if you're only using the _id
pass, don't request _id
and _img
.
If you're capturing the _img
pass, consider encoding images as .jpg rather than lossless .png; the .jpg data is much smaller and can significantly improve simulation speed.
- By default, TDW encodes images as lossless .png
- By default, the
ImageCapture
encodes images as lossy .jpg - To set image encoding, send
set_img_pass_encoding
Note that all other passes are always encoded as lossless .png, even if the _img
pass is .jpg.
Reducing the image size with set_screen_size
will greatly reduce how much data the build needs to send to the controller.
If you don't need image data at all, consider not adding an avatar to the scene. Or, disable the avatar's camera by sending enable_image_sensor
.
IdPassSegmentationColors
can be can be faster than the_id
image pass.Occlusion
can be faster than two_mask
passes- You can use other output data such as
Bounds
to infer much of the same information you'd get from image capture.
Don't request output data that you don't need. Examples:
- If you only need
Transforms
data on the first frame, send{"$type": "send_transforms", "frequency": "once"}
- If you need
Transforms
data on every frame but only for certain objects, send{"$type": "send_transforms", "frequency": "always", "ids": [object_id_0, object_id_1, ...]}
- If you need
Transforms
data for every object on every frame for a span of time, send{"$type": "send_transforms", "frequency": "always"}
and then when you no longer need the data, send{"$type": "send_transforms", "frequency": "never"}
send_collisions
can be slow if"stay"
isTrue
because there are many "stay" events per frame.- Only request static data such as
SegmentationColors
once, when the objects are initially created, and then cache that data.
In general, the more photorealistic the scene, the slower the simulation will be.
Avoid filling the scene with many complex objects. To determine how complex an object is, check record.asset_bundle_sizes
:
from platform import system
from tdw.librarian import ModelLibrarian
librarian = ModelLibrarian()
for record in librarian.records:
print(record.name, record.asset_bundle_sizes[system()])
Using copies of the same model is always faster than using multiple models. TDW must download each model and load it into memory. Once a model has been downloaded and loaded into memory, adding subsequent copies of the model is a near-instantaneous process.
However, it's possible to load too many models into the scene and run out of system memory. To unload models from memory, send unload_asset_bundles
. Be aware that the next time you want to add a model to the scene, TDW will need to download it and load it back into memory.
- Raise and lower the overall render quality by sending
{"$type": "set_render_quality", "render_quality": value}
wherevalue
is an integer between 0 (lowest quality) and 5 (highest quality). - Post-processing can be an expensive process. Disable it by sending
set_post_process
. This will lower image quality. - Disable reflection probes by sending
enable_reflection_probes
. Images will be flatter and less realistic.
Read this for more information.
Next: Good coding practices
Python API:
Command API:
set_img_pass_encoding
set_screen_size
send_transforms
send_collisions
unload_asset_bundles
set_render_quality
set_post_process
enable_reflection_probes
enable_image_sensor
Output Data: