Skip to content

Latest commit

 

History

History
120 lines (75 loc) · 6.59 KB

performance_optimizations.md

File metadata and controls

120 lines (75 loc) · 6.59 KB
Troubleshooting

Performance optimizations

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.

1. Compare your speed to TDW's performance benchmarks

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.

2. Run TDW on a computer with a GPU

You should run TDW on a high-end machine. A powerful GPU is the single most decisive factor in overall performance.

3. Reduce image output data

Image capture is by far the slowest process in TDW.

3A. Only request image data when you need it

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.

3B. Capture .jpg instead of .png

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.

Note that all other passes are always encoded as lossless .png, even if the _img pass is .jpg.

3C. Reduce image size

Reducing the image size with set_screen_size will greatly reduce how much data the build needs to send to the controller.

3D. Disable the image sensor

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.

3E. Use alternative output data

4. Reduce other output data

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" is True 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.

5. Reduce the complexity of the scene

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.

6. Reduce render quality

7. Skip physics frames

Read this for more information.


Next: Good coding practices

Return to the README


Python API:

Command API:

Output Data: