perf(extmarks): better track whether namespace has extmarks (#28615)

This avoids redraw when adding/removing an empty namespace for a window.

This also avoids marktree traversal when clearing a namespace that has
already been cleared, which is added as a benchmark.
This commit is contained in:
zeertzjq
2024-05-03 18:02:25 +08:00
committed by GitHub
parent cf9f002f31
commit d44ed3a885
6 changed files with 89 additions and 11 deletions

View File

@@ -206,7 +206,9 @@ bool extmark_clear(buf_T *buf, uint32_t ns_id, int l_row, colnr_T l_col, int u_r
}
}
bool marks_cleared = false;
bool marks_cleared_any = false;
bool marks_cleared_all = l_row == 0 && l_col == 0;
MarkTreeIter itr[1] = { 0 };
marktree_itr_get(buf->b_marktree, l_row, l_col, itr);
while (true) {
@@ -214,16 +216,29 @@ bool extmark_clear(buf_T *buf, uint32_t ns_id, int l_row, colnr_T l_col, int u_r
if (mark.pos.row < 0
|| mark.pos.row > u_row
|| (mark.pos.row == u_row && mark.pos.col > u_col)) {
if (mark.pos.row >= 0) {
marks_cleared_all = false;
}
break;
}
if (mark.ns == ns_id || all_ns) {
marks_cleared = true;
marks_cleared_any = true;
extmark_del(buf, itr, mark, true);
} else {
marktree_itr_next(buf->b_marktree, itr);
}
}
return marks_cleared;
if (marks_cleared_all) {
if (all_ns) {
map_destroy(uint32_t, buf->b_extmark_ns);
*buf->b_extmark_ns = (Map(uint32_t, uint32_t)) MAP_INIT;
} else {
map_del(uint32_t, uint32_t)(buf->b_extmark_ns, ns_id, NULL);
}
}
return marks_cleared_any;
}
/// @return the position of marks between a range,
@@ -315,10 +330,6 @@ MTPair extmark_from_id(buf_T *buf, uint32_t ns_id, uint32_t id)
/// free extmarks from the buffer
void extmark_free_all(buf_T *buf)
{
if (!map_size(buf->b_extmark_ns)) {
return;
}
MarkTreeIter itr[1] = { 0 };
marktree_itr_get(buf->b_marktree, 0, 0, itr);
while (true) {