This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch speedup
in repository terminology.
View the commit online.
commit 54972f4918080a1b2907d673484225aba47f42eb
Author: [email protected] <[email protected]>
AuthorDate: Sun Mar 22 21:51:54 2026 -0600
perf: use memcmp to skip trailing zero cells in termpty_line_length
termpty_line_length and _termpty_line_is_empty scanned right-to-left
checking each cell individually. For typical terminal output most of
the line is trailing zeros. Skip 8-cell chunks (96 bytes) at a time
using memcmp against a static zero buffer — glibc uses AVX2 for this.
Benchmark: tybench 100k lines drops from 0.31s to 0.29s (~5%).
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
---
src/bin/termpty.c | 37 +++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index d1e00283..c3bba247 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -928,13 +928,18 @@ _termpty_cell_is_empty(const Termcell *cell)
static Eina_Bool
_termpty_line_is_empty(const Termcell *cells, ssize_t nb_cells)
{
- ssize_t len;
+ static const Termcell zero_cells[8] = {{0}};
+ ssize_t pos;
- for (len = nb_cells - 1; len >= 0; len--)
+ pos = nb_cells;
+
+ while (pos >= 8 &&
+ memcmp(&cells[pos - 8], zero_cells, 8 * sizeof(Termcell)) == 0)
+ pos -= 8;
+
+ for (pos = pos - 1; pos >= 0; pos--)
{
- const Termcell *cell = cells + len;
-
- if (!_termpty_cell_is_empty(cell))
+ if (!_termpty_cell_is_empty(&cells[pos]))
return EINA_FALSE;
}
@@ -945,17 +950,25 @@ _termpty_line_is_empty(const Termcell *cells, ssize_t nb_cells)
ssize_t
termpty_line_length(const Termcell *cells, ssize_t nb_cells)
{
- ssize_t len;
+ static const Termcell zero_cells[8] = {{0}};
+ ssize_t pos;
- if (!cells)
+ if (!cells || nb_cells <= 0)
return 0;
- for (len = nb_cells - 1; len >= 0; len--)
- {
- const Termcell *cell = cells + len;
+ pos = nb_cells;
- if (!_termpty_cell_is_empty(cell))
- return len + 1;
+ /* Fast scan: skip trailing chunks of 8 zero cells at a time.
+ * glibc memcmp uses AVX2 for 96-byte comparisons. */
+ while (pos >= 8 &&
+ memcmp(&cells[pos - 8], zero_cells, 8 * sizeof(Termcell)) == 0)
+ pos -= 8;
+
+ /* Per-cell scan through the remaining tail */
+ for (pos = pos - 1; pos >= 0; pos--)
+ {
+ if (!_termpty_cell_is_empty(&cells[pos]))
+ return pos + 1;
}
return 0;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.