aboutsummaryrefslogtreecommitdiff
path: root/src/bun.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-04-22 19:44:23 -0700
committerGravatar GitHub <noreply@github.com> 2023-04-22 19:44:23 -0700
commit4b24bb464c5a54c728bee8c9b4aa30a60c3fb7d4 (patch)
tree7983dd2d5ba18f9a6111be2e7e6d17f69d170bba /src/bun.zig
parent7d6b5f5358617f92ace6f3103dd835ddff73f92a (diff)
downloadbun-4b24bb464c5a54c728bee8c9b4aa30a60c3fb7d4.tar.gz
bun-4b24bb464c5a54c728bee8c9b4aa30a60c3fb7d4.tar.zst
bun-4b24bb464c5a54c728bee8c9b4aa30a60c3fb7d4.zip
Make `Bun.build` more reliable (#2718)
* One possible implementation to make `Bun.build` work better * Pass allocator in * Make our temporary buffers a little safer * rename * Fix memory corruption in symbol table * Add support for deferred idle events in ThreadPool * Free more memory * Use a global allocator FS cache * more `inline` * Make duping keys optional in StringMap * Close file handles more often * Update router.zig * wip possibly delete this commit * Fix memory issues and reduce memory usage * > 0.8 * Switch to AsyncIO.Waker and fix memory leak in JSBundleCompletionTask * We don't need to clone this actually * Fix error * Format * Fixup * Fixup --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to '')
-rw-r--r--src/bun.zig33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/bun.zig b/src/bun.zig
index c6fce74de..e6349fee9 100644
--- a/src/bun.zig
+++ b/src/bun.zig
@@ -20,6 +20,10 @@ else
pub const huge_allocator_threshold: comptime_int = @import("./memory_allocator.zig").huge_threshold;
+/// We cannot use a threadlocal memory allocator for FileSystem-related things
+/// FileSystem is a singleton.
+pub const fs_allocator = default_allocator;
+
pub const C = @import("c.zig");
pub const FeatureFlags = @import("feature_flags.zig");
@@ -1280,12 +1284,14 @@ pub const Schema = @import("./api/schema.zig");
pub const StringMap = struct {
map: Map,
+ dupe_keys: bool = false,
pub const Map = StringArrayHashMap(string);
- pub fn init(allocator: std.mem.Allocator) StringMap {
+ pub fn init(allocator: std.mem.Allocator, dupe_keys: bool) StringMap {
return StringMap{
.map = Map.init(allocator),
+ .dupe_keys = dupe_keys,
};
}
@@ -1311,7 +1317,8 @@ pub const StringMap = struct {
pub fn insert(self: *StringMap, key: []const u8, value: []const u8) !void {
var entry = try self.map.getOrPut(key);
if (!entry.found_existing) {
- entry.key_ptr.* = try self.map.allocator.dupe(u8, key);
+ if (self.dupe_keys)
+ entry.key_ptr.* = try self.map.allocator.dupe(u8, key);
} else {
self.map.allocator.free(entry.value_ptr.*);
}
@@ -1319,13 +1326,20 @@ pub const StringMap = struct {
entry.value_ptr.* = try self.map.allocator.dupe(u8, value);
}
+ pub const put = insert;
+ pub fn get(self: *const StringMap, key: []const u8) ?[]const u8 {
+ return self.map.get(key);
+ }
+
pub fn deinit(self: *StringMap) void {
for (self.map.values()) |value| {
self.map.allocator.free(value);
}
- for (self.map.keys()) |key| {
- self.map.allocator.free(key);
+ if (self.dupe_keys) {
+ for (self.map.keys()) |key| {
+ self.map.allocator.free(key);
+ }
}
self.map.deinit();
@@ -1334,3 +1348,14 @@ pub const StringMap = struct {
pub const DotEnv = @import("./env_loader.zig");
pub const BundleV2 = @import("./bundler/bundle_v2.zig").BundleV2;
+
+pub const Lock = @import("./lock.zig").Lock;
+pub const UnboundedQueue = @import("./bun.js/unbounded_queue.zig").UnboundedQueue;
+
+pub fn threadlocalAllocator() std.mem.Allocator {
+ if (comptime use_mimalloc) {
+ return MimallocArena.getThreadlocalDefault();
+ }
+
+ return default_allocator;
+}