diff options
| author | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-25 21:54:08 -0600 |
|---|---|---|
| committer | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-25 21:54:08 -0600 |
| commit | 87c6a0f8f822c57b4f63bc8bb099a33307871414 (patch) | |
| tree | badd8a2f1485c15280cdf7c64a167b9ffd0e47c5 /bench | |
| parent | c980daddaa17460a65fe1ce7511b680279381dc1 (diff) | |
| download | zash-editor/one-editor.tar.gz | |
interactive: one editor, no libraryeditor/one-editor
libedit was a compile-time alternative (`make EDIT=libedit`). It goes:
FreeBSD and NetBSD `sh` use it because it is in their base system, which
is not the case on z/OS, and it cost about a third of a millisecond to
reach the prompt -- three more shared libraries, `el_init()`, an
`~/.editrc` read and a copy of the history -- for the same cost per key.
What it bought was `~/.editrc` bindings and a kill ring; `bind` and the
built-in editor's own bindings cover the keys, and a second editor meant
a second build mode and a second set of interactive expectations, with
seven tests skipping under it.
Everything that existed only to serve two editors goes with it: the
`EDIT` switch and the two `edit_$(EDIT)` paths in the makefile, the
`$ZASH_EDITOR` variable the tests used to skip, the skip guards in
`tests/linux/`, the NUL stripping in `ptydrive.py` that libedit's redraw
needed, and the parallel paragraphs in README.md, DESIGN.md,
bench/README.md and the two website pages. `bench/README.md` keeps the
measurement, since that is why the decision is written in DESIGN.md.
Checked on Linux (97 passed, 1 skipped, the one known local failure in
linux/i-dscomplete) and on z/OS (64 passed, 3 skipped, 0 failed, plus the
EBCDIC build).
Diffstat (limited to 'bench')
| -rw-r--r-- | bench/README.md | 31 | ||||
| -rw-r--r-- | bench/editor.py | 2 |
2 files changed, 17 insertions, 16 deletions
diff --git a/bench/README.md b/bench/README.md index 9621ba3..128748c 100644 --- a/bench/README.md +++ b/bench/README.md @@ -363,37 +363,38 @@ has no sub-second format. `BENCH_N` sets the number of starts, and ## The line editor -`EDIT=libedit` replaces the built-in editor with libedit, and the two -costs it changes are both in the interactive path, which `run.sh` and -`startup.sh` do not touch. `editor.py` measures them on a +The editor is built in, and `editor.py` is what made that decision easy. +It measures the two costs the off-the-shelf editor changed, both in the +interactive path that `run.sh` and `startup.sh` do not touch, on a pseudo-terminal: `BENCH_N` starts, each timed from just before the fork to the first byte of the prompt, then `BENCH_KEYS` keys typed one at a time, each timed from the write to its echo. ```sh -make EDIT=libedit LDLIBS=-ledit # writes ./zash, keep a copy -cp zash zash-libedit && make zash # the built-in one -python3 bench/editor.py ./zash ./zash-libedit +python3 bench/editor.py ./zash dash bash # any shells, it types at each ``` -Linux, both `-O3`, 20 and then 50 starts, keys medians of 200: +Linux, `-O3`, 20 and then 50 starts, keys medians of 200: | editor | start | one key | | --- | --- | --- | | built-in | 0.94-1.02 ms | 7.2-8.5 us | | libedit | 1.20-1.27 ms | 7.2-7.4 us | -libedit pays about a third of a millisecond more to get to the prompt: -three more shared libraries to load (libedit, ncurses, and the terminfo -entry it reads), `el_init()`, an `~/.editrc` attempt, and the copy of -the shell's history into libedit. Every key costs the same either way; -the round trip is the terminal driver and the scheduler, and the editor's -own work on a key is too small to see through that. +libedit, which zash could be built against (`make EDIT=libedit`) until it +was dropped, paid about a third of a millisecond more to get to the +prompt: three more shared libraries to load (libedit, ncurses, and the +terminfo entry it reads), `el_init()`, an `~/.editrc` attempt, and the +copy of the shell's history into libedit. Every key costs the same either +way; the round trip is the terminal driver and the scheduler, and the +editor's own work on a key is too small to see through that. -So the built-in editor wins a start that never edits, which is the case +So the built-in editor wins the start that never edits, which is the case `make check` and a `#!` line are; for a session spent typing, the two are the same. Neither forks or execs per key, which is the cost that would -have mattered. +have mattered. DESIGN.md records the rest of the reason: FreeBSD and +NetBSD `sh` use libedit because it is in their base system, and z/OS has +no such thing. ## Address mode: 64-bit now diff --git a/bench/editor.py b/bench/editor.py index 6e99cdf..e6d3240 100644 --- a/bench/editor.py +++ b/bench/editor.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """What the line editor costs: start to first prompt, then one key. - bench/editor.py ./zash ./zash-libedit [more shells ...] + bench/editor.py ./zash dash bash [more shells ...] Each shell is started BENCH_N times (default 20) on a pseudo-terminal, the wall clock is read from just before the fork to the first byte of the |
