diff options
author | 2021-12-01 04:48:37 -0800 | |
---|---|---|
committer | 2021-12-16 19:18:51 -0800 | |
commit | da80830bc5ca8674dd2590be9e3f0f686e1d655a (patch) | |
tree | a5e992e7f00865248be30a38eac62c3cfd293f66 | |
parent | b0600564802db8c76da9773699d908b97988db40 (diff) | |
download | bun-da80830bc5ca8674dd2590be9e3f0f686e1d655a.tar.gz bun-da80830bc5ca8674dd2590be9e3f0f686e1d655a.tar.zst bun-da80830bc5ca8674dd2590be9e3f0f686e1d655a.zip |
Mimalloc cleanup
-rw-r--r-- | src/global.zig | 16 | ||||
-rw-r--r-- | src/string_immutable.zig | 10 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/global.zig b/src/global.zig index f8c802841..b01d147d2 100644 --- a/src/global.zig +++ b/src/global.zig @@ -48,7 +48,16 @@ pub const Output = struct { stream: StreamType, err: StreamType, ) Source { + if (comptime Environment.isDebug) { + if (comptime use_mimalloc) { + if (!source_set) { + const Mimalloc = @import("./allocators/mimalloc.zig"); + Mimalloc.mi_option_set(.show_errors, 1); + } + } + } source_set = true; + return Source{ .stream = stream, .error_stream = err, @@ -423,6 +432,13 @@ pub const Global = struct { long_running: bool = false, }; + pub inline fn mimalloc_cleanup() void { + if (comptime use_mimalloc) { + const Mimalloc = @import("./allocators/mimalloc.zig"); + Mimalloc.mi_collect(false); + } + } + // Enabling huge pages slows down Bun by 8x or so // Keeping this code for: // 1. documentation that an attempt was made diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 6657dc27e..5c890b759 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -91,6 +91,14 @@ pub const StringOrTinyString = struct { // allocator.free(slice_); } + pub fn initAppendIfNeeded(stringy: string, comptime Appender: type, appendy: Appender) !StringOrTinyString { + if (stringy.len <= StringOrTinyString.Max) { + return StringOrTinyString.init(stringy); + } + + return StringOrTinyString.init(try appendy.append(string, stringy)); + } + pub fn init(stringy: string) StringOrTinyString { switch (stringy.len) { 0 => { @@ -102,7 +110,7 @@ pub const StringOrTinyString = struct { .is_tiny_string = 1, .remainder_len = @truncate(u7, stringy.len), }; - std.mem.copy(u8, &tiny.remainder_buf, stringy); + @memcpy(&tiny.remainder_buf, stringy.ptr, tiny.remainder_len); return tiny; }, else => { |