diff options
author | 2021-11-02 18:07:11 -0700 | |
---|---|---|
committer | 2021-11-02 18:07:11 -0700 | |
commit | 204d468ad2b71cc3c455c5488167dc734ffe8b41 (patch) | |
tree | 6a4fe5d039046916e588a39d48bdb0d460697010 | |
parent | fbb03425113bbe7f77e161d6f82ef473b0abe2dd (diff) | |
download | bun-204d468ad2b71cc3c455c5488167dc734ffe8b41.tar.gz bun-204d468ad2b71cc3c455c5488167dc734ffe8b41.tar.zst bun-204d468ad2b71cc3c455c5488167dc734ffe8b41.zip |
[internal] Global.configureAllocator()
-rw-r--r-- | src/cli/bun_command.zig | 1 | ||||
-rw-r--r-- | src/cli/create_command.zig | 2 | ||||
-rw-r--r-- | src/cli/dev_command.zig | 4 | ||||
-rw-r--r-- | src/cli/run_command.zig | 4 | ||||
-rw-r--r-- | src/global.zig | 19 |
5 files changed, 27 insertions, 3 deletions
diff --git a/src/cli/bun_command.zig b/src/cli/bun_command.zig index 51c913d5d..a25b33c88 100644 --- a/src/cli/bun_command.zig +++ b/src/cli/bun_command.zig @@ -84,6 +84,7 @@ pub const BunCommand = struct { pub fn exec( ctx: Command.Context, ) !void { + Global.configureAllocator(.{ .long_running = true }); var allocator = ctx.allocator; var log = ctx.log; estimated_input_lines_of_code_ = 0; diff --git a/src/cli/create_command.zig b/src/cli/create_command.zig index fcdc92a66..c559c97f2 100644 --- a/src/cli/create_command.zig +++ b/src/cli/create_command.zig @@ -261,6 +261,8 @@ pub const CreateCommand = struct { var client: HTTPClient = undefined; pub fn exec(ctx: Command.Context, positionals_: []const []const u8) !void { + Global.configureAllocator(.{ .long_running = false }); + var create_options = try CreateOptions.parse(ctx, false); const positionals = create_options.positionals; diff --git a/src/cli/dev_command.zig b/src/cli/dev_command.zig index 91dee1bbc..46c4a0e3c 100644 --- a/src/cli/dev_command.zig +++ b/src/cli/dev_command.zig @@ -1,9 +1,9 @@ const Server = @import("../http.zig").Server; const Command = @import("../cli.zig").Command; - +const Global = @import("../global.zig").Global; pub const DevCommand = struct { pub fn exec(ctx: Command.Context) !void { + Global.configureAllocator(.{ .long_running = true }); try Server.start(ctx.allocator, ctx.args, @TypeOf(ctx.debug), ctx.debug); - } }; diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig index 4593f5f6a..c4c9e5f10 100644 --- a/src/cli/run_command.zig +++ b/src/cli/run_command.zig @@ -487,6 +487,7 @@ pub const RunCommand = struct { if (shebang.len > 2 and strings.eqlComptimeIgnoreLen(shebang[0..2], "#!")) { break :possibly_open_with_bun_js; } + Global.configureAllocator(.{ .long_running = true }); Run.boot(ctx, file, ctx.allocator.dupe(u8, file_path) catch unreachable) catch |err| { if (Output.enable_ansi_colors) { @@ -512,6 +513,9 @@ pub const RunCommand = struct { } } } + + Global.configureAllocator(.{ .long_running = false }); + var args = ctx.args; args.node_modules_bundle_path = null; args.node_modules_bundle_path_server = null; diff --git a/src/global.zig b/src/global.zig index 90a5ca7b5..330c4387c 100644 --- a/src/global.zig +++ b/src/global.zig @@ -1,7 +1,9 @@ const std = @import("std"); pub const Environment = @import("env.zig"); -pub const default_allocator: *std.mem.Allocator = if (isTest) +const use_mimalloc = !Environment.isTest and Environment.isNative; + +pub const default_allocator: *std.mem.Allocator = if (!use_mimalloc) std.heap.c_allocator else @import("./memory_allocator.zig").c_allocator; @@ -77,6 +79,7 @@ pub const Output = struct { } } }; + pub var enable_ansi_colors = isNative; pub var enable_buffering = true; pub var is_stdout_piped = false; @@ -406,6 +409,20 @@ pub const Global = struct { else std.fmt.comptimePrint("0.0.{d}", .{build_id}); + pub const AllocatorConfiguration = struct { + verbose: bool = false, + long_running: bool = false, + }; + + // Enabling huge pages slows down Bun by 8x or so + pub fn configureAllocator(config: AllocatorConfiguration) void { + // if (comptime !use_mimalloc) return; + // const Mimalloc = @import("./allocators/mimalloc.zig"); + // Mimalloc.mi_option_set_enabled(Mimalloc.mi_option_verbose, config.verbose); + // Mimalloc.mi_option_set_enabled(Mimalloc.mi_option_large_os_pages, config.long_running); + // if (!config.long_running) Mimalloc.mi_option_set(Mimalloc.mi_option_reset_delay, 0); + } + pub fn panic(comptime fmt: string, args: anytype) noreturn { @setCold(true); if (comptime isWasm) { |