Skip to content

Core: Switch RID_Alloc::owns to lock-free (reverted)#112657

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
stuartcarnie:rid_alloc_owns_lockfree
Nov 12, 2025
Merged

Core: Switch RID_Alloc::owns to lock-free (reverted)#112657
Repiteo merged 1 commit intogodotengine:masterfrom
stuartcarnie:rid_alloc_owns_lockfree

Conversation

@stuartcarnie
Copy link
Contributor

Summary

Whilst working on #112481 and running various benchmarks, including an MRP that @clayjohn created to test #104194, I observed 7% of the total CPU time was spent in RenderingDevice::texture_is_valid, which in turn calls RID_Alloc::owns. It is owns that spent most of its time acquiring and releasing a mutex. The RID_Alloc::get_or_null API uses atomics for a lock-free approach, which can also be applied to owns, given get_or_null also performs the validation. After the change, texture_is_valid drops from 7.3% to 1.3%:

Clipboard - November 12, 2025 1_01 PM

Copy link
Member

@RandomShaper RandomShaper left a comment

Choose a reason for hiding this comment

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

Makes sense and looks fine to me.

@Ivorforce Ivorforce modified the milestones: 4.x, 4.6 Nov 12, 2025
@Repiteo Repiteo merged commit c9ef313 into godotengine:master Nov 12, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 12, 2025

Thanks!

@stuartcarnie stuartcarnie deleted the rid_alloc_owns_lockfree branch November 12, 2025 18:31
@akien-mga akien-mga changed the title Core: Switch RID_Alloc::owns to lock-free Core: Switch RID_Alloc::owns to lock-free (reverted) Jan 16, 2026
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