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

Use (r)find_char instead of (r)find for single characters #99328

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

AThousandShips
Copy link
Member

This method exists for this dedicated purpose and is faster for these kinds of input

editor/engine_update_label.cpp Outdated Show resolved Hide resolved
modules/svg/image_loader_svg.cpp Outdated Show resolved Hide resolved
scene/resources/font.cpp Outdated Show resolved Hide resolved
@AThousandShips
Copy link
Member Author

Thank you were looking for those but missed them, will convert them

Copy link
Contributor

@Repiteo Repiteo left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

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

Code looks good to me.

@AThousandShips AThousandShips marked this pull request as draft November 16, 2024 21:54
@AThousandShips
Copy link
Member Author

AThousandShips commented Nov 16, 2024

Need to remove a few cases that are in text_server_fb/_adv as they don't support this, forgot that, will do so tomorrow (it doesn't apply to the get_slicec PR I made as that method is exposed to scripting/extensions, but find_char is not)

Will also look at exposing (r)find_char as it's useful for extensions (and get_slicec is exposed)

@AThousandShips AThousandShips marked this pull request as ready for review November 17, 2024 09:02
Copy link
Contributor

@Repiteo Repiteo left a comment

Choose a reason for hiding this comment

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

Reaffirming that this looks good

If we do end up exposing (r)find_char, maybe we should change the name to (r)findc instead. That'd be more inline with get_slicec, and *_char is a bit verbose of a suffix in hindsight

@AThousandShips
Copy link
Member Author

That won't work with extensions sadly, but for future steps it'd be good to keep in mind

@Repiteo Repiteo merged commit 973f16a into godotengine:master Nov 18, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 18, 2024

Thanks!

@AThousandShips
Copy link
Member Author

Thank you!

@clayjohn
Copy link
Member

Folks, I need to insist that performance PRs need need need performance metrics. We absolutely cannot be merging things like this without testing and without confirming that performance does indeed improve.

While the change here makes sense, we still need to validate that before merging otherwise we are just creating noise for potentially no benefit

@AThousandShips AThousandShips deleted the use_find_char branch November 18, 2024 17:08
@AThousandShips
Copy link
Member Author

AThousandShips commented Nov 18, 2024

So to clarify what you mean is specifically measuring the performance gain in-place? As opposed to the fact that these methods are in fact more performant

But I'd question the idea that using the correct method in the correct place, and ensuring uniformity, aren't also objective benefits

@clayjohn
Copy link
Member

So to clarify what you mean is specifically measuring the performance gain in-place? As opposed to the fact that these methods are in fact more performant

Without having tested/profiled, you cannot say whether a given method is indeed more performance than another. Performance improvements are not something you can assert a priori, you can form a hypothesis that this method is faster, but then you actually need to test that hypothesis in the code you are seeking to replace.

To be clear, this code seems like it could be marginally faster than the old code, but we just need to actually show that.

Changes like this create a huge amount of noise in the git repo, they force all contributors to do a full (or nearly full recompile), so they need to be justified.

But I'd question the idea that using the correct method in the correct place, and ensuring uniformity, aren't also objective benefits

They can be, but they aren't valuable enough on their own to justify the costs (noise in git, wasted time in CI, wasted developer time in recompiles, risk of regressions).

At the very least stylistic changes need to be discussed and agreed with people from the core team. The objective benefit comes from having a new style that everyone agrees is better. Switching from one arbitrary style to another that only one person prefers is not an objective benefit.

@AThousandShips
Copy link
Member Author

AThousandShips commented Nov 18, 2024

To be clear, I am aware that's why I asked for clarification not an explanation

Then we'd need some good resources on how to test code in-situ where the assumption that a method which itself is faster is indeed faster in-situ

But I think that's something to discuss elsewhere and from a perspective of resources and review policy

@Ivorforce
Copy link
Contributor

Ivorforce commented Dec 4, 2024

Hi, just dropping in post-mortem to document that single-char find calls are expected to be about 1.24x times as fast as full string finds (for medium length strings, likely to be slightly better for long strings). I tested this as part of #100024 :)

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.

6 participants