Skip to content

Re-computation of AABB every frame in Node3DEditorViewport::_notification is expensive with many nodes #64398

@rcorre

Description

@rcorre

Godot version

4.0.alpha.custom_build.97c0dd74d

System information

Linux 5.18.14-arch1-1

Issue description

When working with voxel_tools, I noticed very high idle CPU usage whenever a VoxelInstancer, or any child of a VoxelInstancer, is selected in the editor: Zylann/godot_voxel#422

It turns out that the 3D viewport recomputes the AABB of every selected node and all their children every frame. voxel_tools uses StaticBody instances in the instancer, so this means it is recomputing 1000s of AABBs every frame, even if the camera is not moving. It might be that voxel_tools could work around this, but it seems like a lot of work to update AABBs that aren't changing.

profile.txt

AABB new_aabb = vi ? vi->get_aabb() : _calculate_spatial_bounds(sp);
appears to be the offending section.

Steps to reproduce

  1. Create a StaticBody
  2. Add 1000s of CollisionShape children
  3. Select the StaticBody in the editor
  4. Note that CPU climbs
  5. Select a single one of the CollisionShape children
  6. Note that CPU drop

Minimal reproduction project

example.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions