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

[Editor, Servers] Minor optimizations #96875

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

stuartcarnie
Copy link
Contributor

The PR introduces a few minor optimisations to prevent double look-ups in hash tables and removes some redundant checks.

@stuartcarnie stuartcarnie requested review from a team as code owners September 11, 2024 19:45
@@ -2246,7 +2246,7 @@ void EditorInspectorArray::_setup() {
}
move_vbox->add_child(ae.move_texture_rect);

if (element_position < _get_array_count() - 1) {
if (element_position < count - 1) {
Copy link
Contributor Author

@stuartcarnie stuartcarnie Sep 11, 2024

Choose a reason for hiding this comment

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

Counts are cached at the top of the function:

// Setup counts.
count = _get_array_count();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only perform a single lookup in the hash table

@@ -150,12 +150,10 @@ void RenderingServerDefault::_draw(bool p_swap_buffers, double frame_step) {

double time = frame_profile[i + 1].gpu_msec - frame_profile[i].gpu_msec;

if (name[0] != '<' && name[0] != '>') {
Copy link
Contributor Author

@stuartcarnie stuartcarnie Sep 11, 2024

Choose a reason for hiding this comment

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

This if was redundant given the earlier check in the loop:

if (name[0] == '<' || name[0] == '>') {
continue;
}

Comment on lines -141 to -145
if (!dependency_map.has(p_depends_on)) {
dependency_map[p_depends_on] = HashSet<RID>();
HashSet<RID> *set = dependency_map.getptr(p_depends_on);
if (set == nullptr) {
set = &dependency_map.insert(p_depends_on, HashSet<RID>())->value;
}
set->insert(p_id);

dependency_map[p_depends_on].insert(p_id);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The improvement removes a hash table lookup, as it calls getptr to the value and only if it is nullptr, does it insert it. Overall this function performs 2 less hash-table lookups per call.

@stuartcarnie stuartcarnie force-pushed the sgc/small_optimisations branch from 1cd642a to 5bc5d7a Compare September 11, 2024 20:19
@stuartcarnie stuartcarnie force-pushed the sgc/small_optimisations branch from 5bc5d7a to 5cfacc8 Compare September 11, 2024 20:22
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Looks fine to me!

@clayjohn clayjohn added this to the 4.4 milestone Sep 11, 2024
@akien-mga akien-mga changed the title [Editor,Servers]: Minor optimizations [Editor, Servers] Minor optimizations Sep 12, 2024
@akien-mga akien-mga merged commit 573badf into godotengine:master Sep 12, 2024
20 checks passed
@akien-mga
Copy link
Member

Thanks!

@stuartcarnie stuartcarnie deleted the sgc/small_optimisations branch September 12, 2024 22:33
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.

4 participants