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

Don't instantiate ColorPicker in EditorPropertyColor constructor #101570

Merged
merged 1 commit into from
Jan 21, 2025

Conversation

larspet
Copy link
Contributor

@larspet larspet commented Jan 15, 2025

The EditorPropertyColor constructor was using ColorPickerButton::get_popup() and ColorPickerButton::get_picker(), which was instantiating the ColorPicker without it being opened first. This led to 40+ pickers being instantiated in some cases.

This PR avoids calling those getters by using the ColorPickerButton::picker_created signal to setup the picker at a later stage.

On a debug build I get these results (quickly measured by eye & timer):

  • Opening Editor Settings > Text Editor > Theme:
    • Master: 2 sec
    • This PR: instant
  • Opening the MRP inspector:
    • Master: 1.5 sec
    • This PR: 0.2 sec (must be other Node properties making it not instant)

Switching away to another setting or inspector is faster now too, since there's no need to delete all the pickers.

@Chaosus Chaosus added this to the 4.4 milestone Jan 15, 2025
@AThousandShips AThousandShips requested a review from a team January 15, 2025 08:59
@KoBeWi
Copy link
Member

KoBeWi commented Jan 19, 2025

You can use picker_created signal.

@larspet
Copy link
Contributor Author

larspet commented Jan 19, 2025

You can use picker_created signal.

I was considering that, but that signal is only emitted once right? I need the signal to be emitted every time it's opened. Unless I use picker_created to connect to about_to_popup (and also disconnect from picker_created). But that feels a little convoluted.

@KoBeWi
Copy link
Member

KoBeWi commented Jan 19, 2025

You only need picker_created for the setup, the remaining code can be in about_to_popup like now.
The reason picker was created in constructor was bind(picker->get_picker()).

@larspet larspet force-pushed the color-picker-pickle branch from a85e747 to 3376ba6 Compare January 20, 2025 23:34
picker->connect("popup_closed", callable_mp(this, &EditorPropertyColor::_popup_closed), CONNECT_DEFERRED);
picker->get_popup()->connect("about_to_popup", callable_mp(EditorNode::get_singleton(), &EditorNode::setup_color_picker).bind(picker->get_picker()));
picker->get_popup()->connect("about_to_popup", callable_mp(this, &EditorPropertyColor::_picker_opening));
picker->connect("picker_created", callable_mp(this, &EditorPropertyColor::_picker_created), CONNECT_ONE_SHOT);
Copy link
Member

Choose a reason for hiding this comment

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

ONE_SHOT is not needed, because the signal is emitted only once anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can lump this in alongside the later fix you mentioned

Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

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

Seems like picker_created was already used before, but was replaced in #62581.

For editor properties we could call setup_color_picker() only once. Also the setup method can be changed to take button instead, so popups are not created early (there is a few of them in the editor).

That's for later though, this fix is fine for now.

@Repiteo Repiteo merged commit a7146ef into godotengine:master Jan 21, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Jan 21, 2025

Thanks!

@larspet larspet deleted the color-picker-pickle branch January 21, 2025 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inspector loads slowly when there's many Color properties
4 participants