From 03e04a6726244b7ff046a1d978dc3fbecd8ef86e Mon Sep 17 00:00:00 2001 From: HuJK Date: Tue, 27 Oct 2026 19:51:04 +0800 Subject: [PATCH] Bridge: mimalloc as the global allocator The runtime allocates and frees on every encoder call; the system allocator's frees from the encoding thread also returned pages to the kernel (madvise). Every allocation of the bridge and the runtime is freed on the Rust side (handles are Box::into_raw and Box::from_raw), so the allocator is the Rust side's alone. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012Camiwa7VsPwkhfyscKQ6S --- bridge/NativeMetalBridge.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bridge/NativeMetalBridge.rs b/bridge/NativeMetalBridge.rs index 40a753f..4c8d698 100644 --- a/bridge/NativeMetalBridge.rs +++ b/bridge/NativeMetalBridge.rs @@ -11,6 +11,12 @@ #[path = "NativeMetalObjects.rs"] pub mod objects; +/// The runtime allocates and frees on every encoder call (binding tables, recorded calls, tracked uses); mimalloc's thread-local free +/// lists take those small blocks for less than the system allocator, whose frees from the encoding thread also gave pages back to the +/// kernel (madvise) as they emptied. Every allocation of the bridge and the runtime is the Rust side's own, freed there. +#[global_allocator] +static ALLOCATOR: mimalloc::MiMalloc = mimalloc::MiMalloc; + use metal2vulkan::metal::{PixelFormat, PrimitiveType, TextureUsage}; use metal2vulkan::pipeline::{ColorAttachmentDescriptor, RenderPipelineDescriptor, StageSource}; use metal2vulkan_runtime::{