From ee451fe345cc86263d0ab5d0f81aa3c296595516 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Thu, 24 Nov 2022 20:43:54 -0600 Subject: [PATCH] Common: Fix slow emulator startup on M1s --- common/AlignedMalloc.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/AlignedMalloc.cpp b/common/AlignedMalloc.cpp index adc76fdb8e..5db3b40246 100644 --- a/common/AlignedMalloc.cpp +++ b/common/AlignedMalloc.cpp @@ -28,6 +28,11 @@ void* _aligned_malloc(size_t size, size_t align) #if defined(__USE_ISOC11) && !defined(ASAN_WORKAROUND) // not supported yet on gcc 4.9 return aligned_alloc(align, size); #else +#ifdef __APPLE__ + // MacOS has a bug where posix_memalign is ridiculously slow on unaligned sizes + // This especially bad on M1s for some reason + size = (size + align - 1) & ~(align - 1); +#endif void* result = 0; posix_memalign(&result, align, size); return result;