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

Exit early in TextEdit::_get_column_pos_of_word to improve highlight performance #80809

Conversation

jsjtxietian
Copy link
Contributor

@jsjtxietian jsjtxietian commented Aug 20, 2023

This pr fixes #80801
If in the while loop inside _get_column_pos_of_word, string.find or findn can't find any match words, we can just early break the while loop to imporove cpu performance.
In the origin logic without early break, p_from_column will only plus 1 every loop, this means basically this function will do the string.find or findn for p_search.length times, this is way too slow for a long p_search string.

Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

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

Fix makes sense, haven't tested myself though

Just a style thing to fix

scene/gui/text_edit.cpp Outdated Show resolved Hide resolved
match words, just early break the while loop. This
will improve a lot when p_search.length is way too
long since p_from_column will only plus 1 every loop
@jsjtxietian jsjtxietian force-pushed the early-quit-in-_get_column_pos_of_word branch from 40166c2 to 70dad7e Compare August 20, 2023 13:49
@AThousandShips AThousandShips changed the title Early quit in TextEdit::_get_column_pos_of_word to improve hightlight performace Edit early in TextEdit::_get_column_pos_of_word to improve hightlight performace Aug 20, 2023
@akien-mga akien-mga changed the title Edit early in TextEdit::_get_column_pos_of_word to improve hightlight performace Edit early in TextEdit::_get_column_pos_of_word to improve highlight performace Aug 21, 2023
@akien-mga akien-mga merged commit 76a4b5d into godotengine:master Aug 21, 2023
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@jsjtxietian jsjtxietian deleted the early-quit-in-_get_column_pos_of_word branch August 21, 2023 07:31
@akien-mga akien-mga changed the title Edit early in TextEdit::_get_column_pos_of_word to improve highlight performace Exit early in TextEdit::_get_column_pos_of_word to improve highlight performace Sep 5, 2023
@akien-mga akien-mga changed the title Exit early in TextEdit::_get_column_pos_of_word to improve highlight performace Exit early in TextEdit::_get_column_pos_of_word to improve highlight performance Nov 29, 2023
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.

Editor crashes if trying to highlight part of a really long line of text.
3 participants