diff options
author | 2022-03-31 04:55:47 -0700 | |
---|---|---|
committer | 2022-03-31 04:55:47 -0700 | |
commit | 89cd35f07fdb2e965e3518f3417e4c39f0163522 (patch) | |
tree | 20233096d6e5f3629e21522d3dab1e0ef80b4f86 /src/cache.zig | |
parent | 7b2ab994e554184c7bdfbbc9ed8977314334cecc (diff) | |
download | bun-89cd35f07fdb2e965e3518f3417e4c39f0163522.tar.gz bun-89cd35f07fdb2e965e3518f3417e4c39f0163522.tar.zst bun-89cd35f07fdb2e965e3518f3417e4c39f0163522.zip |
[bun dev] Improve HMR reliability when filesystem is slow or reading large files
Diffstat (limited to 'src/cache.zig')
-rw-r--r-- | src/cache.zig | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/src/cache.zig b/src/cache.zig index 6a13726d6..b9ad273d1 100644 --- a/src/cache.zig +++ b/src/cache.zig @@ -61,6 +61,7 @@ pub const Fs = struct { macro_shared_buffer: MutableString, is_macro_mode: bool = false, + stream: bool = false, // When we are in a macro, the shared buffer may be in use by the in-progress macro. // so we have to dynamically switch it out. @@ -80,7 +81,7 @@ pub const Fs = struct { } pub fn readFileShared( - _: *Fs, + this: *Fs, _fs: *fs.FileSystem, path: [:0]const u8, _: StoredFileDescriptorType, @@ -100,12 +101,20 @@ pub const Fs = struct { } } - const file = rfs.readFileWithHandle(path, null, file_handle, true, shared) catch |err| { - if (comptime Environment.isDebug) { - Output.printError("{s}: readFile error -- {s}", .{ path, @errorName(err) }); + const file = if (this.stream) + rfs.readFileWithHandle(path, null, file_handle, true, shared, true) catch |err| { + if (comptime Environment.isDebug) { + Output.printError("{s}: readFile error -- {s}", .{ path, @errorName(err) }); + } + return err; } - return err; - }; + else + rfs.readFileWithHandle(path, null, file_handle, true, shared, false) catch |err| { + if (comptime Environment.isDebug) { + Output.printError("{s}: readFile error -- {s}", .{ path, @errorName(err) }); + } + return err; + }; return Entry{ .contents = file.contents, @@ -151,12 +160,20 @@ pub const Fs = struct { } } - const file = rfs.readFileWithHandle(path, null, file_handle, use_shared_buffer, c.sharedBuffer()) catch |err| { - if (Environment.isDebug) { - Output.printError("{s}: readFile error -- {s}", .{ path, @errorName(err) }); + const file = if (c.stream) + rfs.readFileWithHandle(path, null, file_handle, use_shared_buffer, c.sharedBuffer(), true) catch |err| { + if (Environment.isDebug) { + Output.printError("{s}: readFile error -- {s}", .{ path, @errorName(err) }); + } + return err; } - return err; - }; + else + rfs.readFileWithHandle(path, null, file_handle, use_shared_buffer, c.sharedBuffer(), false) catch |err| { + if (Environment.isDebug) { + Output.printError("{s}: readFile error -- {s}", .{ path, @errorName(err) }); + } + return err; + }; return Entry{ .contents = file.contents, |