Slow down of the application when rebuilding a widget frequently


I have an issue with the tutorial omni.example.ui_scene.object_info (kit-extension-sample-ui-scene/exts/omni.example.ui_scene.object_info at main · NVIDIA-Omniverse/kit-extension-sample-ui-scene · GitHub ).
I wanted to use this extension as a starting point to create a similar extension with values that change in real time but also with potentially the content of the widget changing (adding text, values, images, etc). The problem is, after a while, the application slows down a lot. If I put a counter, I notice that this is after a hundred rebuilds of the widget.

To recreate a minimal version of the problem by starting from the extension omni.example.ui_scene.object_info and change:

  • In the class WidgetInfoManipulator in on_bluid the line :
    self._widget = sc.Widget(500, 150, update_policy=sc.Widget.UpdatePolicy.ON_HOVERED)
    by self._widget = sc.Widget(500, 150, update_policy=sc.Widget.UpdatePolicy.ALWAYS).

  • In the class WidgetInfoManipulator in on_model_updated add at the end, the line :

  • In the class WidgetInfoModel in __init__, add at the end, the lines:
    self.__viewport_api = vp_utils.get_active_viewport_window().viewport_api and self.__frame_changed_sub = self.__viewport_api.subscribe_to_frame_change(self.update_model_state).

  • In the class WidgetInfoManipulator creates the function update_model_state:

    def update_model_state(self, _):

Moreover, as soon as I restart the extension, the application becomes fluid again (the number of FPS increases) and as soon as I activate the rebuild of the widget every frame, the number of FPS decreases dramatically.

After some tests, I think it’s not because I rebuild the frame at each update (i.e. self._widget.frame.rebuild()), but rather because I rebuild the widget each time with the update_policy=sc.Widget.UpdatePolicy.ALWAYS option.

Thanks a lot!


Hi Felix. I think you may have a cyclical execution there. If WidgetInfoManipulator.on_model_update() call WidgetInfoManipulator.frame.rebuild(), WidgetInfoManipulator.on_model_update() will get called again during the rebuild in WidgetInfoManipulator._on_build_widgets()`.

You’re likely going to run into performance or flickering problems trying to rebuild the frame in real-time. Ideally, you want to update the widget models in real-time and the widgets will take care of updating themselves without a frame rebuild.

1 Like

Hi Mati,
I didn’t know that the WidgetInfoManipulator.frame.rebuild() will also call the WidgetInfoManipulator.on_model_updated(). I thought the latter was only called when the model associated with the manipulator was modified (with a self._item_changed for example). Thanks for the quick reply.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.