Make cold bun install use 2x less memory (#3271)

* Make cold `bun install` use 2x less memory

In this benchmark: https://github.com/orogene/orogene/blob/main/BENCHMARKS.md

This brings us from around 2.7 GB to 1.2 GB of memory

* Address comments

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2023-06-10 15:38:09 -07:00
committed by GitHub
parent 04cd6a82b8
commit 02eafd5019
3 changed files with 69 additions and 43 deletions

View File

@@ -235,6 +235,13 @@ pub const MutableString = struct {
return self.list.items;
}
/// Clear the existing value without freeing the memory or shrinking the capacity.
pub fn move(self: *MutableString) []u8 {
const out = self.list.items;
self.list = .{};
return out;
}
pub fn toOwnedSentinelLeaky(self: *MutableString) [:0]u8 {
if (self.list.items.len > 0 and self.list.items[self.list.items.len - 1] != 0) {
self.list.append(