Skip to content

Merge the two Object mutexes to save on RAM (1/4 down).#119985

Open
Ivorforce wants to merge 1 commit into
godotengine:masterfrom
Ivorforce:object-single-mutex
Open

Merge the two Object mutexes to save on RAM (1/4 down).#119985
Ivorforce wants to merge 1 commit into
godotengine:masterfrom
Ivorforce:object-single-mutex

Conversation

@Ivorforce
Copy link
Copy Markdown
Member

@Ivorforce Ivorforce commented Jun 2, 2026

What problem(s) does this PR solve?

Reduces non-Node Object size by ~88 bytes, which is around 1/4 of their total size (assuming empty).

Additional information

There's no real need to have two separate mutexes. Access to both is rare, and mutexes are huge.

Performance should be the same as before, or better. Object instantiation should be measurably faster (no additional allocation).

Note: Mostly untested right now (except for a quick compile and unit test/editor run).
The main risk I see is if I misinterpreted the signal code and this change introduces some deadlock potential.

@Ivorforce Ivorforce added this to the 4.x milestone Jun 2, 2026
@Ivorforce Ivorforce requested a review from hpvb June 2, 2026 23:53
@Ivorforce Ivorforce requested a review from a team as a code owner June 2, 2026 23:53
@Ivorforce Ivorforce requested review from RandomShaper and mihe June 2, 2026 23:54
Comment thread core/object/object.cpp
Comment on lines -71 to +72
Mutex *mutex1 = nullptr;
Mutex *mutex2 = nullptr;
BinaryMutex *mutex1 = nullptr;
BinaryMutex *mutex2 = nullptr;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are code paths that lock recursively, so changing to BinaryMutex will presumably cause a deadlock. See Object::_add_user_signal and Object::add_user_signal.

There might be more, I'm not sure.

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.

2 participants