diff options
Diffstat (limited to 'test/lspbench.zig')
| -rw-r--r-- | test/lspbench.zig | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/test/lspbench.zig b/test/lspbench.zig index d0e25aee..08df9f4c 100644 --- a/test/lspbench.zig +++ b/test/lspbench.zig @@ -110,8 +110,13 @@ test "lspbench options reject unknown flags and multiple roots before probing" { try std.testing.expectError(error.MultipleRoots, Options.parse(&.{ "first", "--check", "second" })); } +/// The process's Io, for the queries: their waits are woken by the client's +/// reader threads, which a single-threaded Io cannot be. +var query_io: std.Io = undefined; + pub fn main(init: std.process.Init) !void { const gpa = std.heap.page_allocator; + query_io = init.io; const args = try init.minimal.args.toSlice(init.arena.allocator()); if (args.len > 1 and std.mem.eql(u8, args[1], "probe")) return probeCommand(init); @@ -171,13 +176,19 @@ fn checkResults(results: []const Result, required: usize) !void { for (results) |r| if (r.empty or !r.correct) return error.IncorrectProbe; } -fn runOnce(gpa: std.mem.Allocator, req: lsp.Req, expected: []const u8, r: *Result) !u64 { - var arena: std.heap.ArenaAllocator = .init(gpa); - defer arena.deinit(); +fn runOnce(gpa: std.mem.Allocator, req_in: lsp.Req, expected: []const u8, r: *Result) !u64 { + // The editor's own path (host_io.Lsp.work): the query in the fixed + // region reserved at startup, not a heap arena that maps its memory anew. + const memory = @import("pardes").memory; + const region = memory.takeLspQuery() orelse return error.QueryRegionBusy; + var arena: std.heap.FixedBufferAllocator = .init(region); + defer memory.giveLspQuery(arena.end_index); + var req = req_in; + req.budget = &arena; var out: std.Io.Writer.Allocating = .init(gpa); defer out.deinit(); const t0 = nowNs(); - try lsp.query(gpa, arena.allocator(), req, &out.writer); + try lsp.query(query_io, gpa, arena.allocator(), req, &out.writer); const ns = nowNs() -| t0; r.accept(out.written(), expected); return ns / 1000; @@ -341,6 +352,7 @@ extern "c" fn usleep(usec: c_uint) c_int; /// [--reps N] [--warm S]`, rows on stdout, the timing on stderr. fn probeCommand(init: std.process.Init) !void { const gpa = std.heap.page_allocator; + query_io = init.io; const arena = init.arena.allocator(); const io = std.Io.Threaded.global_single_threaded.io(); @@ -431,7 +443,7 @@ fn probeCommand(init: std.process.Init) !void { var scratch: std.heap.ArenaAllocator = .init(gpa); defer scratch.deinit(); const t0 = nowUs(); - try lsp.query(gpa, scratch.allocator(), .{ + try lsp.query(query_io, gpa, scratch.allocator(), .{ .kind = kind, .path = path, .source = source, |
