From 3b12041c7a38647028a6e43c2481837fe7615ad9 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Mon, 13 Jul 2026 20:24:47 +0200 Subject: [PATCH] Use mimalloc as the Python allocator instead of preloading jemalloc (#175604) Co-authored-by: Claude Opus 4.8 (1M context) --- rootfs/etc/services.d/home-assistant/run | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/rootfs/etc/services.d/home-assistant/run b/rootfs/etc/services.d/home-assistant/run index 40ec07c15431..950c6a6250e3 100755 --- a/rootfs/etc/services.d/home-assistant/run +++ b/rootfs/etc/services.d/home-assistant/run @@ -5,9 +5,14 @@ cd /config || bashio::exit.nok "Can't find config folder!" -# Enable mimalloc for Home Assistant Core, unless disabled -if [[ -z "${DISABLE_JEMALLOC+x}" ]]; then - export LD_PRELOAD="/usr/local/lib/libjemalloc.so.2" - export MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:20000,muzzy_decay_ms:20000" +# Use mimalloc as Python's object allocator by default. It is bundled in CPython +# (3.13+), so no LD_PRELOAD or extra library is required, and it uses noticeably +# less memory than the previously preloaded jemalloc. Override or disable via +# PYTHONMALLOC, e.g. `PYTHONMALLOC=pymalloc` for the default allocator. +export PYTHONMALLOC="${PYTHONMALLOC:-mimalloc}" + +if [[ -n "${DISABLE_JEMALLOC+x}" ]]; then + bashio::log.warning "DISABLE_JEMALLOC is set but no longer has any effect: jemalloc has been replaced by mimalloc. Set PYTHONMALLOC=pymalloc to use the default allocator instead." fi + exec python3 -m homeassistant --config /config