Cache result of keycode_get_count() for a small Speedup#121727
Open
og-mrk wants to merge 1 commit into
Open
Conversation
Co-authored-by: kobewi <kobewi4e@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brief Description
keycode_get_countis being called every iteration of the for loop, even though it never changes, this PR caches the result to avoid unnecessary calls tokeycode_get_countfunction.Testing
Compiled & tested Godot on Windows 11 with an Intel i7-6700K CPU, running at a constant 4.00GHz speed.
build options used:
target=editor dev_mode=yes optimaze=speed d3d12=no accesskit=noTesting methodology is the following:
get_ticks_usec()to capture thestart&endtimes, and calculated the difference to know how long the for loop have taken.Ain the filter input field, then delete it, then re-add it, then deleted it, and so on... (to capture multiple data points, and calculate the average)Aas a filter (takes less, because there's less things to do).Benchmark Results
Tried keeping background processes at a minimum, but I'm on Windows, so take these results with a grain of salt 🧂
Additional information
This change was suggested by @KoBeWi in this discussion, I've tried @bruvzg's idea of making
keycode_get_countaconstexprfunction.. but it somehow made the code slower? likely my fault as I'm new to C++Also out of topic question.. why is this code called 4 times when opening a project (when the editor starts up)? the dialog window isn't visible to user, maybe I'm missing something?
Use of AI
No AI was used in the process of making these changes.