diff options
author | 2023-08-24 19:39:00 -0700 | |
---|---|---|
committer | 2023-08-24 19:39:00 -0700 | |
commit | 8a48e8bb0b7de985a96b3a4cae389e3294a2c0e3 (patch) | |
tree | 20d8dc382512313061c20296d1e33e8d18fbbde3 /src/bun.js/webcore/blob.zig | |
parent | 097ae4e982a9cbcae6b4886c4efb82d452629b99 (diff) | |
download | bun-8a48e8bb0b7de985a96b3a4cae389e3294a2c0e3.tar.gz bun-8a48e8bb0b7de985a96b3a4cae389e3294a2c0e3.tar.zst bun-8a48e8bb0b7de985a96b3a4cae389e3294a2c0e3.zip |
Report extra memory more (#4289)
* Report memory allocated in fetch
* Memory size reporting to `Headers`
* Fixup memory reporting allocator
* Make these tests do more
* cleanup some of this
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/webcore/blob.zig')
-rw-r--r-- | src/bun.js/webcore/blob.zig | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig index c5e893a5a..604726c1e 100644 --- a/src/bun.js/webcore/blob.zig +++ b/src/bun.js/webcore/blob.zig @@ -1233,6 +1233,34 @@ pub const Blob = struct { return blob_; } + fn estimatedByteSize(this: *Blob) usize { + // in-memory size. not the size on disk. + if (this.size != Blob.max_size) { + return this.size; + } + + var store = this.store orelse return 0; + if (store.data == .bytes) { + return store.data.bytes.len; + } + + return 0; + } + + pub fn estimatedSize(this: *Blob) callconv(.C) usize { + var size = this.estimatedByteSize() + @sizeOf(Blob); + + if (this.store) |store| { + size += @sizeOf(Blob.Store); + size += switch (store.data) { + .bytes => store.data.bytes.stored_name.len, + .file => store.data.file.pathlike.path.slice().len, + }; + } + + return size + (this.content_type.len * @as(usize, @intFromBool(this.content_type_allocated))); + } + comptime { if (!JSC.is_bindgen) { _ = JSDOMFile__hasInstance; |