Skip to content

Fixing mimalloc memory-limit crash#324

Merged
robbiehanson merged 1 commit intomasterfrom
mimalloc-fix
Dec 15, 2022
Merged

Fixing mimalloc memory-limit crash#324
robbiehanson merged 1 commit intomasterfrom
mimalloc-fix

Conversation

@robbiehanson
Copy link
Contributor

I was testing receiving payments when Phoenix was running in the background, and noticed that it had mysteriously stopped working in recent builds. I tracked down the issue and discovered the the notification-service-extension was crashing:

Screenshot 2022-12-14 at 10 25 02

This issue is that Apple limits the amount of memory that a notification-service-extension is allowed to use. The memory is capped at 24 MB (for iOS 16).

In the Kotlin docs, they say:

Another way to fix high memory consumption is related to mimalloc, the default memory allocator for many targets. It pre-allocates and holds onto the system memory to improve the allocation speed.

To avoid that at the cost of performance, a couple of options are available:

  • Switch the memory allocator from mimalloc to the system allocator. For that, set the -Xallocator=std compilation option in your Gradle build script.

  • Since Kotlin 1.8.0-Beta, you can also instruct mimalloc to promptly release memory back to the system. It's a smaller performance cost, but it gives less definitive results.

The "-Xallocator=std" option seems to do the trick, as I wasn't able to reproduce the crash with that option set. In fact, the memory is significantly lowered:

Screenshot 2022-12-14 at 10 36 42

I don't notice any performance degradation. In fact, fetching objects from the database actually seems faster. But I can appreciate how mimalloc theoretically increases performance. So I'd be happy to revisit this when we adopt Kotlin 1.8. Or if Apple raises the memory limits in future versions of iOS.

@robbiehanson robbiehanson requested a review from dpad85 December 14, 2022 15:59
@robbiehanson robbiehanson merged commit f5e3cb3 into master Dec 15, 2022
@robbiehanson robbiehanson deleted the mimalloc-fix branch December 15, 2022 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants