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

Integrate mimalloc allocator #99686

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RandomShaper
Copy link
Member

@RandomShaper RandomShaper commented Nov 25, 2024

I noticed #99427, an integration of mimalloc.

Since I already had an integration in a private fork, I've decided to upstream it so we can decide which one is the preferred way.

Main highlight is that this is a low-level integration: as such it also hooks into allocations made by 3rd-party code (TLS storage, C/C++ standard library containers, 3rd-party libraries, etc.).

Disclaimer:
This has been thoroughly tested downstream on Windows and certain non-standard platforms. This PR would need some work to add the low-level integration to all the other platforms. On Mac it may work out-of-the-box, though.

2024-11-26:

  • PR updated enabling the allocator for all platforms. Note, again, I only tested this on Windows, but the integration is slightly different now, so a little smoke test would be needed again. Other platforms need full testing.
  • I've had to put mimalloc as its own first-level element (as a sibling of core, drivers, etc.) because most platforms need it to be linked first for reliable overriding of malloc() and friends.

2024-11-26 (2):

  • OK, obviously, Mac still needs work (as well as .NET-enabled builds), but this is good enough for review.

drivers/mimalloc/SCsub Outdated Show resolved Hide resolved
@RandomShaper RandomShaper force-pushed the godot_mimalloc branch 5 times, most recently from 8bd1a51 to 43f1217 Compare November 26, 2024 13:15
@RandomShaper RandomShaper marked this pull request as ready for review November 26, 2024 16:30
@RandomShaper RandomShaper requested a review from a team as a code owner November 26, 2024 16:30
Copy link
Contributor

@Repiteo Repiteo left a comment

Choose a reason for hiding this comment

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

Conceptually, I like the low-level approach a lot more. It'd be great if you could provide some performance metrics once you feel the PR is in a presentable state!

Comment on lines 118 to 122
#if 0 // This one doesn't work.
__declspec(restrict) unsigned short *wcsdup(const unsigned short *s) {
return mi_wcsdup(s);
}
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Any further context for why this one doesn't work, and how relevant it is compared to the rest of the functions?

Copy link
Member Author

Choose a reason for hiding this comment

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

error C2733: 'wcsdup': you cannot overload a function with 'extern "C"' linkage

I've rewritten this file and now it's more "traceable" and contains remarks.

mimalloc/SCsub Outdated Show resolved Hide resolved
mimalloc/SCsub Outdated Show resolved Hide resolved
mimalloc/SCsub Outdated Show resolved Hide resolved
mimalloc/SCsub Outdated Show resolved Hide resolved
@DeeJayLSP
Copy link
Contributor

DeeJayLSP commented Dec 14, 2024

If it helps somehow, I tried an approach of mimalloc a while ago: DeeJayLSP@eae9709

However, getting it to work properly was beyond my knowledge. I observed there is a MI_TSAN define.

One thing that I did manage to do however, was linking with the system-provided mimalloc for Linux packages using pkg-config mimalloc --cflags --libs.

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