X Tutup
Skip to content

Do not zero elements and perform fast clear in HashMap#108932

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
Nazarwadim:hash_map_final_optimization
Nov 17, 2025
Merged

Do not zero elements and perform fast clear in HashMap#108932
Repiteo merged 1 commit intogodotengine:masterfrom
Nazarwadim:hash_map_final_optimization

Conversation

@Nazarwadim
Copy link
Contributor

This is optimizations from #90082.

The first optimization is that it is not necessary for the element pointers to be null, since the hashes are already null.

Second, the elements are cleared, such as in a linked list, and then the hashes and pointers to the elements are freed. This will eliminate iteration over hashes and elements and result in the elements being freed in the order they were inserted.

@Nazarwadim Nazarwadim requested a review from a team as a code owner July 24, 2025 14:10
Copy link
Member

@Ivorforce Ivorforce left a comment

Choose a reason for hiding this comment

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

All 3 optimizations make sense to me, thanks!
Not setting elements to non-nullptr is probably the riskiest of the bunch, but I don't see element nullptr checks, and technically we shouldn't need them to be defined anyway when hash is EMPTY_HASH.

@Ivorforce Ivorforce added this to the 4.6 milestone Jul 26, 2025
@AThousandShips AThousandShips changed the title Do not zeroed elements and fast clear in HashMap Do not zero elements and perform fast clear in HashMap Jul 28, 2025
@Repiteo
Copy link
Contributor

Repiteo commented Nov 13, 2025

Needs rebase

@Nazarwadim Nazarwadim force-pushed the hash_map_final_optimization branch from b54bc88 to e6bc3fa Compare November 14, 2025 09:33
@Repiteo Repiteo merged commit 359ef8f into godotengine:master Nov 17, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 17, 2025

Thanks!

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.

3 participants

X Tutup