From 8da986ea877b07a5eb117446f410f2a7fc8cd9cb Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 13 Sep 2023 13:39:18 +0200 Subject: refactor(grid): change schar_T representation to be more compact Previously, a screen cell would occupy 28+4=32 bytes per cell as we always made space for up to MAX_MCO+1 codepoints in a cell. As an example, even a pretty modest 50*80 screen would consume 50*80*2*32 = 256000, i e a quarter megabyte With the factor of two due to the TUI side buffer, and even more when using msg_grid and/or ext_multigrid. This instead stores a 4-byte union of either: - a valid UTF-8 sequence up to 4 bytes - an escape char which is invalid UTF-8 (0xFF) plus a 24-bit index to a glyph cache This avoids allocating space for huge composed glyphs _upfront_, while still keeping rendering such glyphs reasonably fast (1 hash table lookup + one plain index lookup). If the same large glyphs are using repeatedly on the screen, this is still a net reduction of memory/cache consumption. The only case which really gets worse is if you blast the screen full with crazy emojis and zalgo text and even this case only leads to 4 extra bytes per char. When only <= 4-byte glyphs are used, plus the 4-byte attribute code, i e 8 bytes in total there is a factor of four reduction of memory use. Memory which will be quite hot in cache as the screen buffer is scanned over in win_line() buffer text drawing A slight complication is that the representation depends on host byte order. I've tested this manually by compling and running this in qemu-s390x and it works fine. We might add a qemu based solution to CI at some point. --- src/nvim/ugrid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ugrid.c') diff --git a/src/nvim/ugrid.c b/src/nvim/ugrid.c index be1746983c..d3a1097aba 100644 --- a/src/nvim/ugrid.c +++ b/src/nvim/ugrid.c @@ -4,6 +4,7 @@ #include #include +#include "nvim/grid.h" #include "nvim/memory.h" #include "nvim/ugrid.h" @@ -79,8 +80,7 @@ static void clear_region(UGrid *grid, int top, int bot, int left, int right, sat { for (int row = top; row <= bot; row++) { UGRID_FOREACH_CELL(grid, row, left, right + 1, { - cell->data[0] = ' '; - cell->data[1] = 0; + cell->data = schar_from_ascii(' '); cell->attr = attr; }); } -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/ugrid.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/ugrid.c') diff --git a/src/nvim/ugrid.c b/src/nvim/ugrid.c index d3a1097aba..3a422ff2f2 100644 --- a/src/nvim/ugrid.c +++ b/src/nvim/ugrid.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include -- cgit From 28f4f3c48498086307ed825d1761edb5789ca0e8 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 15:54:54 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment - use bool to represent boolean values --- src/nvim/ugrid.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nvim/ugrid.c') diff --git a/src/nvim/ugrid.c b/src/nvim/ugrid.c index 3a422ff2f2..f02b9626cd 100644 --- a/src/nvim/ugrid.c +++ b/src/nvim/ugrid.c @@ -61,10 +61,8 @@ void ugrid_scroll(UGrid *grid, int top, int bot, int left, int right, int count) step = -1; } - int i; - // Copy cell data - for (i = start; i != stop; i += step) { + for (int i = start; i != stop; i += step) { UCell *target_row = grid->cells[i] + left; UCell *source_row = grid->cells[i + count] + left; assert(right >= left && left >= 0); -- cgit