Skip to content

Per Entity sprite picking (and maybe friends) opt-out #17108

@Phoqinu

Description

@Phoqinu

What problem does this solve or what need does it fill?

Currently sprite_picking is relatively expensive, I did some light testing with tracy and 200k sprites with like only 2k of them being in camera view can result in the sprite_picking taking 500µs. Which is not much but frame time was 2.66ms so it took "only" almost 20% of frame time.

I don't need picking for my sprites and in debug mode - without any bevy optimizations - the performace penalty is so big that you can reach single digit fps.

My specific use-case aside I can imagine that some people would want picking only for some sprites and they might want to turn off picking for the rest.

What solution would you like?

For sprite_picking a simple component:

#[derive(Debug, Component)]
pub struct NoSpritePicking;

then in the sprite_picking system sprite query could be modified from:

sprite_query: Query<(
        Entity,
        &Sprite,
        &GlobalTransform,
        Option<&PickingBehavior>,
        &ViewVisibility,
    )>,

to

sprite_query: Query<(
        Entity,
        &Sprite,
        &GlobalTransform,
        Option<&PickingBehavior>,
        &ViewVisibility,
    ), Without<NoSpritePicking>>,

Then users if they don't want picking for their sprites they can just add NoSpritePicking component to sprite entity.

What alternative(s) have you considered?

I tried adding PickingBehavior::IGNORE to my sprites but that did not bring any speed-up.

Maybe it could result in some weird behavior with PickingBehavior ? idk

I think it would be nice to have similar marking ignore components for other backends.
Maybe even global NoPicking component or something ?

Faster and better sprite_picking system ?- It's currently doing filtering, sorting and filtering on all sprites...

Picking being opt-in ?

Additional context

Red - current default system with/out PickingBehavior
Yellow - my proposed feature with NoSpritePicking on my sprites and modified system
200k sprites (2k on camera, rest off-camera), release mode

(This is for my use-case, ofc different apps won't probably see similar speed-up)
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-PickingPointing at and selecting objects of all sortsC-PerformanceA change motivated by improving speed, memory usage or compile timesD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions