feat: improve did_change performance with an arena
This commit is contained in:
parent
d05fbcae37
commit
d60ad49f84
1 changed files with 21 additions and 21 deletions
|
@ -315,27 +315,28 @@ pub fn did_open(self: *Self, file_path: []const u8, file_type: []const u8, langu
|
|||
pub fn did_change(self: *Self, file_path: []const u8, version: usize, root_dst_addr: usize, root_src_addr: usize, eol_mode: Buffer.EolMode) LspError!void {
|
||||
const lsp = try self.get_language_server(file_path);
|
||||
const uri = try self.make_URI(file_path);
|
||||
defer self.allocator.free(uri);
|
||||
|
||||
var arena_ = std.heap.ArenaAllocator.init(self.allocator);
|
||||
const arena = arena_.allocator();
|
||||
var scratch_alloc: ?[]u32 = null;
|
||||
defer {
|
||||
const frame = tracy.initZone(@src(), .{ .name = "deinit" });
|
||||
self.allocator.free(uri);
|
||||
arena_.deinit();
|
||||
frame.deinit();
|
||||
if (scratch_alloc) |scratch|
|
||||
self.allocator.free(scratch);
|
||||
}
|
||||
|
||||
const root_dst: Buffer.Root = if (root_dst_addr == 0) return else @ptrFromInt(root_dst_addr);
|
||||
const root_src: Buffer.Root = if (root_src_addr == 0) return else @ptrFromInt(root_src_addr);
|
||||
|
||||
var dizzy_edits = std.ArrayListUnmanaged(dizzy.Edit){};
|
||||
var dst = std.ArrayList(u8).init(self.allocator);
|
||||
var src = std.ArrayList(u8).init(self.allocator);
|
||||
var scratch = std.ArrayListUnmanaged(u32){};
|
||||
var edits_cb = std.ArrayList(u8).init(self.allocator);
|
||||
var dst = std.ArrayList(u8).init(arena);
|
||||
var src = std.ArrayList(u8).init(arena);
|
||||
var edits_cb = std.ArrayList(u8).init(arena);
|
||||
const writer = edits_cb.writer();
|
||||
|
||||
defer {
|
||||
const frame = tracy.initZone(@src(), .{ .name = "deinit" });
|
||||
edits_cb.deinit();
|
||||
dst.deinit();
|
||||
src.deinit();
|
||||
scratch.deinit(self.allocator);
|
||||
dizzy_edits.deinit(self.allocator);
|
||||
frame.deinit();
|
||||
}
|
||||
{
|
||||
const frame = tracy.initZone(@src(), .{ .name = "store" });
|
||||
defer frame.deinit();
|
||||
|
@ -343,17 +344,17 @@ pub fn did_change(self: *Self, file_path: []const u8, version: usize, root_dst_a
|
|||
try root_src.store(src.writer(), eol_mode);
|
||||
}
|
||||
const scratch_len = 4 * (dst.items.len + src.items.len) + 2;
|
||||
{
|
||||
const scratch = blk: {
|
||||
const frame = tracy.initZone(@src(), .{ .name = "scratch" });
|
||||
defer frame.deinit();
|
||||
try scratch.ensureTotalCapacity(self.allocator, scratch_len);
|
||||
}
|
||||
scratch.items.len = scratch_len;
|
||||
break :blk try self.allocator.alloc(u32, scratch_len);
|
||||
};
|
||||
scratch_alloc = scratch;
|
||||
|
||||
{
|
||||
const frame = tracy.initZone(@src(), .{ .name = "diff" });
|
||||
defer frame.deinit();
|
||||
try dizzy.PrimitiveSliceDiffer(u8).diff(self.allocator, &dizzy_edits, src.items, dst.items, scratch.items);
|
||||
try dizzy.PrimitiveSliceDiffer(u8).diff(arena, &dizzy_edits, src.items, dst.items, scratch);
|
||||
}
|
||||
var lines_dst: usize = 0;
|
||||
var last_offset: usize = 0;
|
||||
|
@ -398,8 +399,7 @@ pub fn did_change(self: *Self, file_path: []const u8, version: usize, root_dst_a
|
|||
{
|
||||
const frame = tracy.initZone(@src(), .{ .name = "send" });
|
||||
defer frame.deinit();
|
||||
var msg = std.ArrayList(u8).init(self.allocator);
|
||||
defer msg.deinit();
|
||||
var msg = std.ArrayList(u8).init(arena);
|
||||
const msg_writer = msg.writer();
|
||||
try cbor.writeMapHeader(msg_writer, 2);
|
||||
try cbor.writeValue(msg_writer, "textDocument");
|
||||
|
|
Loading…
Add table
Reference in a new issue