summaryrefslogtreecommitdiffstatshomepage
path: root/scripts
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2025-09-29 13:18:59 +0200
committerbfredl <bjorn.linse@gmail.com>2025-10-18 11:36:16 +0200
commite656d7be2ee194665e5d1c6f28ac5fc8487b7010 (patch)
treed71426506cc408c015da6e5edd7233bdf676f3f5 /scripts
parent671841673e7b66f4f40a49a000a6a46e662f802e (diff)
perf(tui): faster implementation of terminfo
The processing of terminfo can be separated into two steps: 1. The initialization of terminfo, which includes trying to find $TERM in a terminfo database file. As a fallback, common terminfo definitions are compiled in. After this, we apply a lot of ad-hoc patching to cover over limitations of terminfo. 2. While processing updates from nvim, actually using terminfo strings and formatting them with runtime values. for this part, terminfo essentially is a hyper-enhanced version of snprintf(), including a sm0l stack based virtual machine which can manipulate the runtime parameters. This PR completely replaces libuniblium for step 2, with code vendored from NetBSD's libtermkey which has been adapted to use typesafe input parameters and to write into an output buffer in place. The most immedatiate effects is a performance enhancement of update_attrs() which is a very hot function when profiling the TUI-process part of screen updates. In a stupid microbenchmark (essentially calling nvim__screenshot over and over in a loop) this leads to a speedup of ca 1.5x for redrawing the screen on the TUI-side. What this means in practise when using nvim as a text editor is probably no noticible effect at all, and when reabusing nvim as idk a full screen RGB ASCII art rendrer maybe an increase from 72 to 75 FPS LMAO. As nice side-effect, reduce the usage of unibilium to initialization only.. which will make it easier to remove, replace or make unibilium optional, adressing #31989. Specifically, the builtin fallback doesn't use unibilium at all, so a unibilium-free build is in principle possible if the builtin definitions are good enough. As a caveat, this PR doesn't touch libtermkey at all, which still has a conditional dependency on unibilium. This will be investigated in a follow-up PR Note: the check of $TERMCOLOR was moved from tui/tui.c to _defaults.lua in d7651b27d54a87c5783c0a579af11da9a16a39aa as we want to skip the logic in _defaults.lua if the env var was set, but there is no harm in TUI getting the right value when the TUI is trying to initialize its terminfo shenanigans. Also this check is needed when a TUI connects to a `--headless` server later, which will observe a different $TERMCOLOR value than the nvim core process itself.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/update_terminfo.sh87
1 files changed, 0 insertions, 87 deletions
diff --git a/scripts/update_terminfo.sh b/scripts/update_terminfo.sh
deleted file mode 100755
index 34525dec32..0000000000
--- a/scripts/update_terminfo.sh
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/usr/bin/env bash
-#
-# usage: ./scripts/update_terminfo.sh
-#
-# This script does:
-#
-# 1. Download Dickey's terminfo.src
-# 2. Compile temporary terminfo database from terminfo.src
-# 3. Use database to generate src/nvim/tui/terminfo_defs.h
-#
-
-set -e
-
-url='https://invisible-island.net/datafiles/current/terminfo.src.gz'
-target='src/nvim/tui/terminfo_defs.h'
-
-readonly -A entries=(
- [ansi]=ansi_terminfo
- [interix]=interix_8colour_terminfo
- [iterm2]=iterm_256colour_terminfo
- [linux]=linux_16colour_terminfo
- [putty-256color]=putty_256colour_terminfo
- [rxvt-256color]=rxvt_256colour_terminfo
- [screen-256color]=screen_256colour_terminfo
- [st-256color]=st_256colour_terminfo
- [tmux-256color]=tmux_256colour_terminfo
- [vte-256color]=vte_256colour_terminfo
- [xterm-256color]=xterm_256colour_terminfo
- [cygwin]=cygwin_terminfo
- [win32con]=win32con_terminfo
- [conemu]=conemu_terminfo
- [vtpcon]=vtpcon_terminfo
-)
-
-db="$(mktemp -du)"
-
-print_bold() {
- printf "\\e[1m%b\\e[0m" "$*"
-}
-
-cd "$(git rev-parse --show-toplevel)"
-
-#
-# Get terminfo.src
-#
-print_bold '[*] Get terminfo.src\n'
-curl -O "$url"
-gunzip -f terminfo.src.gz
-
-#
-# Build terminfo database
-#
-print_bold '[*] Build terminfo database\n'
-cat terminfo.src scripts/windows.ti | tic -x -o "$db" -
-rm -f terminfo.src
-
-#
-# Write src/nvim/tui/terminfo_defs.h
-#
-print_bold "[*] Writing $target... "
-sorted_terms="$(echo "${!entries[@]}" | tr ' ' '\n' | sort | xargs)"
-
-cat > "$target" <<EOF
-// uncrustify:off
-
-// Generated by scripts/update_terminfo.sh and $(tic -V)
-
-#pragma once
-
-#include <stdint.h>
-EOF
-
-for term in $sorted_terms; do
- path="$(find "$db" -name "$term")"
- if [ -z "$path" ]; then
- >&2 echo "Not found: $term. Skipping."
- continue
- fi
- printf '\n'
- infocmp -L -x -1 -A "$db" "$term" | sed -e '1d' -e 's#^#// #' | tr '\t' ' '
- printf 'static const int8_t %s[] = {\n' "${entries[$term]}"
- printf ' '
- od -v -t d1 < "$path" | cut -c9- | xargs | tr ' ' ','
- printf '};\n'
-done >> "$target"
-
-print_bold 'done\n'