mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 04:18:58 +00:00
Simplify mimalloc alignment check (#21497)
This slightly reduces memory use. Maximum memory use of `bun test html-rewriter`, averaged across 100 iterations: * 101975 kB without this change * 101634 kB with this change I also tried changing the code to always use the aligned allocation functions, but this slightly increased memory use, to 102160 kB. (For internal tracking: fixes ENG-19866)
This commit is contained in:
@@ -13,7 +13,7 @@ fn mimalloc_free(
|
||||
// but its good to have that assertion
|
||||
// let's only enable it in debug mode
|
||||
if (comptime Environment.isDebug) {
|
||||
if (mimalloc.canUseAlignedAlloc(buf.len, alignment.toByteUnits()))
|
||||
if (mimalloc.mustUseAlignedAlloc(alignment))
|
||||
mimalloc.mi_free_size_aligned(buf.ptr, buf.len, alignment.toByteUnits())
|
||||
else
|
||||
mimalloc.mi_free_size(buf.ptr, buf.len);
|
||||
@@ -28,7 +28,7 @@ const MimallocAllocator = struct {
|
||||
if (comptime Environment.enable_logs)
|
||||
log("mi_alloc({d}, {d})", .{ len, alignment.toByteUnits() });
|
||||
|
||||
const ptr: ?*anyopaque = if (mimalloc.canUseAlignedAlloc(len, alignment.toByteUnits()))
|
||||
const ptr: ?*anyopaque = if (mimalloc.mustUseAlignedAlloc(alignment))
|
||||
mimalloc.mi_malloc_aligned(len, alignment.toByteUnits())
|
||||
else
|
||||
mimalloc.mi_malloc(len);
|
||||
@@ -82,7 +82,7 @@ const ZAllocator = struct {
|
||||
fn alignedAlloc(len: usize, alignment: mem.Alignment) ?[*]u8 {
|
||||
log("ZAllocator.alignedAlloc: {d}\n", .{len});
|
||||
|
||||
const ptr = if (mimalloc.canUseAlignedAlloc(len, alignment.toByteUnits()))
|
||||
const ptr = if (mimalloc.mustUseAlignedAlloc(alignment))
|
||||
mimalloc.mi_zalloc_aligned(len, alignment.toByteUnits())
|
||||
else
|
||||
mimalloc.mi_zalloc(len);
|
||||
|
||||
Reference in New Issue
Block a user