Skip to content

increase default thread stack size #7476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bun.js/web_worker.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub const WebWorker = struct {
worker.cpp_worker = ptr;

var thread = std.Thread.spawn(
.{ .stack_size = bun.default_stack_size },
.{ .stack_size = bun.default_thread_stack_size },
startWithErrorHandling,
.{worker},
) catch {
Expand Down
2 changes: 1 addition & 1 deletion src/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ pub const AsyncIO = @import("async_io");

pub const logger = @import("./logger.zig");
pub const ThreadPool = @import("./thread_pool.zig");
pub const default_stack_size = ThreadPool.default_stack_size;
pub const default_thread_stack_size = ThreadPool.default_thread_stack_size;
pub const picohttp = @import("./deps/picohttp.zig");
pub const uws = @import("./deps/uws.zig");
pub const BoringSSL = @import("./boringssl.zig");
Expand Down
2 changes: 1 addition & 1 deletion src/http.zig
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ pub const HTTPThread = struct {

const thread = try std.Thread.spawn(
.{
.stack_size = bun.default_stack_size,
.stack_size = bun.default_thread_stack_size,
},
comptime onStart,
.{
Expand Down
2 changes: 1 addition & 1 deletion src/network_thread.zig
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub fn init() !void {
global.waker = try AsyncIO.Waker.init(@import("root").bun.default_allocator);
}

global.thread = try std.Thread.spawn(.{ .stack_size = bun.default_stack_size }, onStartIOThread, .{
global.thread = try std.Thread.spawn(.{ .stack_size = bun.default_thread_stack_size }, onStartIOThread, .{
global.waker,
});
global.thread.detach();
Expand Down
12 changes: 6 additions & 6 deletions src/thread_pool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Sync = packed struct {
/// Configuration options for the thread pool.
/// TODO: add CPU core affinity?
pub const Config = struct {
stack_size: u32 = default_stack_size,
stack_size: u32 = default_thread_stack_size,
max_threads: u32,
};

Expand Down Expand Up @@ -440,9 +440,9 @@ inline fn notify(self: *ThreadPool, is_waking: bool) void {
return self.notifySlow(is_waking);
}

pub const default_stack_size = brk: {
// 2mb
const default = 2 * 1024 * 1024;
pub const default_thread_stack_size = brk: {
// 4mb
const default = 4 * 1024 * 1024;

if (!Environment.isMac) break :brk default;

Expand Down Expand Up @@ -473,7 +473,7 @@ pub fn warm(self: *ThreadPool, count: u14) void {
.Release,
.Monotonic,
) orelse break));
const spawn_config = std.Thread.SpawnConfig{ .stack_size = default_stack_size };
const spawn_config = std.Thread.SpawnConfig{ .stack_size = default_thread_stack_size };
const thread = std.Thread.spawn(spawn_config, Thread.run, .{self}) catch return self.unregister(null);
thread.detach();
}
Expand Down Expand Up @@ -515,7 +515,7 @@ noinline fn notifySlow(self: *ThreadPool, is_waking: bool) void {

// We signaled to spawn a new thread
if (can_wake and sync.spawned < self.max_threads) {
const spawn_config = std.Thread.SpawnConfig{ .stack_size = default_stack_size };
const spawn_config = std.Thread.SpawnConfig{ .stack_size = default_thread_stack_size };
const thread = std.Thread.spawn(spawn_config, Thread.run, .{self}) catch return self.unregister(null);
// if (self.name.len > 0) thread.setName(self.name) catch {};
return thread.detach();
Expand Down
2 changes: 1 addition & 1 deletion src/work_pool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn NewWorkPool(comptime max_threads: ?usize) type {

pool = ThreadPool.init(.{
.max_threads = max_threads orelse @max(@as(u32, @truncate(std.Thread.getCpuCount() catch 0)), 2),
.stack_size = ThreadPool.default_stack_size,
.stack_size = ThreadPool.default_thread_stack_size,
});
return &pool;
}
Expand Down