aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-05-27 00:42:02 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-05-27 00:42:02 -0700
commitfeb7adcd087f1999daad4058dc7864aed6fc4796 (patch)
tree98426e9234c6abc6e72cbacbe3417c63a2091079 /src
parent84be179f7cc578335797f0e09847db3f3f8bd92a (diff)
downloadbun-feb7adcd087f1999daad4058dc7864aed6fc4796.tar.gz
bun-feb7adcd087f1999daad4058dc7864aed6fc4796.tar.zst
bun-feb7adcd087f1999daad4058dc7864aed6fc4796.zip
faster writes performance
Former-commit-id: 2c212929f8d94e08dfe8794154dc45cc97924458
Diffstat (limited to 'src')
-rw-r--r--src/allocators.zig4
-rw-r--r--src/cli.zig33
2 files changed, 30 insertions, 7 deletions
diff --git a/src/allocators.zig b/src/allocators.zig
index ebf2186dc..541eb145d 100644
--- a/src/allocators.zig
+++ b/src/allocators.zig
@@ -105,7 +105,7 @@ pub fn hash_eqlFn(a: HashKeyType, b: HashKeyType) bool {
return a == b;
}
-pub const ItemStatus = packed enum(u3) {
+pub const ItemStatus = enum(u3) {
unknown,
exists,
not_found,
@@ -589,6 +589,6 @@ pub fn BSSMap(comptime ValueType: type, comptime count: anytype, store_keys: boo
};
}
-fn constStrToU8(s: []const u8) []u8 {
+pub fn constStrToU8(s: []const u8) []u8 {
return @intToPtr([*]u8, @ptrToInt(s.ptr))[0..s.len];
}
diff --git a/src/cli.zig b/src/cli.zig
index e24d257b9..27e834bb8 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -322,18 +322,41 @@ pub const Cli = struct {
if (args.write) |write| {
if (write) {
+ var open_file_limit: usize = 32;
+
+ if (std.os.getrlimit(.NOFILE)) |limit| {
+ open_file_limit = limit.cur;
+ } else |err| {}
+ const do_we_need_to_close = open_file_limit > result.output_files.len * 2;
did_write = true;
- var root_dir = try std.fs.openDirAbsolute(args.absolute_working_dir.?, std.fs.Dir.OpenDirOptions{});
+ var root_dir = try std.fs.openDirAbsolute(result.outbase, std.fs.Dir.OpenDirOptions{});
defer root_dir.close();
for (result.output_files) |f| {
- try root_dir.makePath(std.fs.path.dirname(f.path) orelse unreachable);
+ var fp = f.path;
+ if (fp[0] == std.fs.path.sep) {
+ fp = fp[1..];
+ }
- var _handle = try std.fs.createFileAbsolute(f.path, std.fs.File.CreateFlags{
+ var _handle = root_dir.createFile(fp, std.fs.File.CreateFlags{
.truncate = true,
- });
+ }) catch |err| brk: {
+ // Only bother to create the directory if there's an error because that's probably why it errored
+ if (std.fs.path.dirname(fp)) |dirname| {
+ root_dir.makePath(dirname) catch {};
+ }
+
+ // Then, retry!
+ break :brk (root_dir.createFile(fp, std.fs.File.CreateFlags{
+ .truncate = true,
+ }) catch |err2| return err2);
+ };
try _handle.seekTo(0);
- defer _handle.close();
+ defer {
+ if (do_we_need_to_close) {
+ _handle.close();
+ }
+ }
try _handle.writeAll(f.contents);
}