Fix clogged up git operations.
This commit is contained in:
+24
-5
@@ -6,6 +6,7 @@
|
||||
//! else — process management, rendering, and the GTK4 UI — lives here.
|
||||
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const adw = @import("adw");
|
||||
const gio = @import("gio");
|
||||
|
||||
@@ -21,10 +22,28 @@ pub const std_options: std.Options = .{
|
||||
.log_level = .info,
|
||||
};
|
||||
|
||||
var gpa: std.heap.DebugAllocator(.{}) = .init;
|
||||
/// The process allocator, which everything in the app shares: the GTK main
|
||||
/// loop, every terminal's parser, and every review connection thread.
|
||||
///
|
||||
/// `DebugAllocator` only in a debug build, and this is not a matter of taste.
|
||||
/// It is thread-safe by way of one mutex around every allocation and every
|
||||
/// free, and its backing allocator is the page allocator — so a large
|
||||
/// allocation is an `mmap` and its release an `munmap`, both taken under that
|
||||
/// single process-wide lock. A review pane's poll allocates a whole `git diff`
|
||||
/// and drops it a moment later, several times a second across a handful of open
|
||||
/// reviews, and each one of those was stalling the main loop and every other
|
||||
/// request behind the same lock. `c_allocator` has a per-thread cache and no
|
||||
/// global lock; libc is already linked for GTK.
|
||||
var debug_gpa: std.heap.DebugAllocator(.{}) = .init;
|
||||
|
||||
fn gpa() std.mem.Allocator {
|
||||
return if (builtin.mode == .Debug) debug_gpa.allocator() else std.heap.c_allocator;
|
||||
}
|
||||
|
||||
pub fn main() u8 {
|
||||
defer _ = gpa.deinit();
|
||||
defer if (builtin.mode == .Debug) {
|
||||
_ = debug_gpa.deinit();
|
||||
};
|
||||
|
||||
// Before the allocator's own teardown, since the settings arena comes out
|
||||
// of it. A no-op if the app never got as far as activating.
|
||||
@@ -51,7 +70,7 @@ pub fn main() u8 {
|
||||
fn onActivate(app: *adw.Application, _: ?*anyopaque) callconv(.c) void {
|
||||
// The file both of the next two read from: the scheme, and the tabs the
|
||||
// window opens itself with.
|
||||
Settings.init(gpa.allocator());
|
||||
Settings.init(gpa());
|
||||
|
||||
// Before the window, so that the first frame is drawn in the scheme the
|
||||
// user chose rather than repainted into it a moment later.
|
||||
@@ -65,9 +84,9 @@ fn onActivate(app: *adw.Application, _: ?*anyopaque) callconv(.c) void {
|
||||
// created and every terminal is handed the endpoint of the tab it opens in.
|
||||
// Started unconditionally rather than on the first review pane, so an agent
|
||||
// running in a tab has a `PLAYPEN_REVIEW_URL` from the moment it starts.
|
||||
review.init(gpa.allocator());
|
||||
review.init(gpa());
|
||||
|
||||
const window = Window.create(gpa.allocator(), app) catch |err| {
|
||||
const window = Window.create(gpa(), app) catch |err| {
|
||||
std.log.err("failed to create window: {s}", .{@errorName(err)});
|
||||
return;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user