Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of 3D scenes by initializing all objects at once #3022

Merged
merged 2 commits into from
May 6, 2024

Conversation

falkoschindler
Copy link
Contributor

This PR experiments with sending a single initialization message with all 3D objects at once to reduce the time for creating complex 3D scenes like discussed in #3009.

A demo with 10,000 boxes runs even faster than with PR #3017:

with ui.scene() as scene:
    scene.move_camera(y=-6, z=7)
    for x in range(100):
        for y in range(100):
            scene.box().scale(0.09).move(x / 10 - 5, y / 10 - 5)

This approach not only bundles multiple commands into one message, it also cuts the payload significantly by focusing on the actual data rather the sending loads of overhead for every attribute. It could be combined with PR #3017 to improve the speed for updating existing objects.

@falkoschindler falkoschindler added the enhancement New feature or request label May 5, 2024
@falkoschindler falkoschindler changed the title Improve performance of 3D scene by initializing all objects at once Improve performance of 3D scenes by initializing all objects at once May 5, 2024
@falkoschindler falkoschindler self-assigned this May 5, 2024
Copy link

@kovalp kovalp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me see how this behaves.

self._visible()
self._draggable()
@property
def data(self) -> List[Any]:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use a simple method, not a property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you think a method would be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A method is easier to mock to facilitate unit testing.

Ok, I see your point. I'd like to stick with the property nonetheless, because mocking this property for a unit test is not a concert at the moment and a property feels more idiomatic in this case.

@kovalp
Copy link

kovalp commented May 6, 2024

This performs great! There is almost no delay for the shape 50x50 and maybe half-a-second delay for the 100x100 field.

Does this PR improve the updates too?

@falkoschindler falkoschindler added this to the 1.4.24 milestone May 6, 2024
@kovalp
Copy link

kovalp commented May 6, 2024 via email

@falkoschindler
Copy link
Contributor Author

Does this PR improve the updates too?

@kovalp No, this PR only improves the object initialization. Updates will be tackled by PR #3017 or other improvements.

Anyway, I think we should merge this PR because it greatly improves the ui.scene element.

@falkoschindler falkoschindler marked this pull request as ready for review May 6, 2024 09:49
@falkoschindler falkoschindler merged commit ec74e6a into main May 6, 2024
7 checks passed
@falkoschindler falkoschindler deleted the init-3d-objects branch May 6, 2024 09:49
@kovalp
Copy link

kovalp commented May 6, 2024 via email

@kovalp
Copy link

kovalp commented May 7, 2024

Is this improvement effective for existing scenes or only for the newly created scenes?

@falkoschindler
Copy link
Contributor Author

@kovalp It should also improve the performance when creating new scenes dynamically, e.g. on button click. Every scene sends an "init" event to the server which responds with an "init_objects" message containing all 3D object information. Thus it benefits from the new condensed format.

@kovalp
Copy link

kovalp commented May 7, 2024 via email

@falkoschindler
Copy link
Contributor Author

As I said in #3022 (comment), updates to existing objects will be addressed by PR #3017 and other improvements.

@kovalp
Copy link

kovalp commented May 7, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants