Repository navigation
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #662 +/- ##
==========================================
+ Coverage 61.99% 62.10% +0.11%
==========================================
Files 29 29
Lines 5091 5091
Branches 1082 1081 -1
==========================================
+ Hits 3156 3162 +6
+ Misses 1595 1590 -5
+ Partials 340 339 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
tony
marked this pull request as ready for review
April 29, 2026 00:59
tony
force-pushed
the
2026-04-perf-and-profiling
branch
from
April 29, 2026 01:11
feec66f to
5c4fc6e
Compare
tony
force-pushed
the
2026-04-perf-and-profiling
branch
from
May 10, 2026 16:15
5c4fc6e to
c715085
Compare
6 tasks done
tony
added a commit
to tmux-python/tmuxp
that referenced
this pull request
May 10, 2026
Pin $SHELL=/bin/sh in an autouse pytest fixture so tmux test panes spawn /bin/sh instead of the contributor's interactive shell. tmux falls back to $SHELL for new panes when default-shell is unset, so the env var pin is sufficient — no .tmux.conf override needed. On systems with slow shell init (zsh + oh-my-zsh, heavy bash profile chains) this can roughly halve `uv run py.test` wall time; on stripped-down shells the gain is smaller. No effect on `tmuxp load`, `tmuxp freeze`, or workspace YAML behavior — contributor test runs only. The fixture is function-scoped so `monkeypatch.setenv` restores the prior value at teardown. Once libtmux PR #662 (which pins the same env var in libtmux's pytest plugin) merges and ships in a libtmux release tmuxp picks up, this commit becomes redundant and can be reverted cleanly. See also: tmux-python/libtmux#662
tony
force-pushed
the
2026-04-perf-and-profiling
branch
from
May 30, 2026 14:00
c715085 to
3b4006f
Compare
tony
force-pushed
the
2026-04-perf-and-profiling
branch
from
July 4, 2026 13:40
3b4006f to
280f38b
Compare
tony
force-pushed
the
2026-04-perf-and-profiling
branch
from
July 18, 2026 11:01
280f38b to
ad7c1a5
Compare
tony
force-pushed
the
2026-04-perf-and-profiling
branch
from
November 7, 2026 09:42
ad7c1a5 to
de731d0
Compare
tony
force-pushed
the
2026-04-perf-and-profiling
branch
6 times, most recently
from
November 28, 2026 12:49
6666cf5 to
94a83e4
Compare
tony
force-pushed
the
2026-04-perf-and-profiling
branch
from
November 29, 2026 02:47
94a83e4 to
d26094d
Compare
tony
added a commit
to zappolowski/tmuxp
that referenced
this pull request
Nov 29, 2026
why: Profiling tmuxp's test suite showed the dominant per-pane cost was tmux spawning the contributor's interactive \$SHELL — typically ``/bin/zsh`` with a full rcfile chain (oh-my-zsh, plugins, prompt themes, etc.) — for every pane created across the suite. Each init costs ~60ms warm and up to ~400ms cold; multiplied across hundreds of pane spawns in workspace/builder tests, that's the single largest line item in suite wall time. tmux falls back to ``\$SHELL`` for new panes when ``default-shell`` is unset (the default in libtmux's bundled test ``.tmux.conf``), so monkey-patching \$SHELL=/bin/sh in an autouse function-scoped fixture forces every test pane to spawn ``/bin/sh`` instead. Empty rcfiles, deterministic prompt, no plugin chains. A/B measured locally with the project's standard ``uv run py.test`` (defaults: ``--reruns=0 --doctest-modules``): master ~76-78s pytest, ~71s wall this branch (1st run) 37.01s pytest, 35.08s wall this branch (2nd run) 36.24s pytest, 34.29s wall That's a ~51% wall-time reduction, consistent with the upstream libtmux PR (tmux-python/libtmux#662) that pins the same env var in libtmux's pytest plugin and reports a similar "~70s -> ~32s" delta. Applying the pin at the tmuxp conftest level lands the gain immediately without waiting for the libtmux PR to merge and release; once libtmux ships the upstream pin, this commit becomes redundant and can be reverted cleanly. what: - conftest.py: add ``_pin_test_shell_env`` function-scoped autouse fixture that calls ``monkeypatch.setenv("SHELL", "/bin/sh")``. ``monkeypatch`` restores the prior value at teardown so no global state leaks across tests or out of pytest's process. - Leading-underscore name signals "internal autouse plumbing" — no test should depend on it explicitly. - USING_ZSH constant and ``zshrc`` autouse-on-USING_ZSH fixture retained for now; they become dead at runtime once \$SHELL is always ``/bin/sh`` (no zsh first-run greeting to suppress) but the cleanup is left as a follow-up to keep this commit's diff minimal and the perf claim independently revertible.
why: Profiling tmuxp's test suite showed 80% of the ~62s wall time was shell/fixture overhead, not tmux commands. The dominant cost was every tmux pane spawning the developer's $SHELL — typically /bin/zsh — which costs ~60ms of init per pane (cold ~400ms) and produces non-deterministic prompt output that flakes capture-pane assertions. A/B confirmed SHELL=/bin/sh cuts the full tmuxp suite from ~70s to ~32s (2.2x faster) and eliminates a flaky test. what: - pytest_plugin.config_file: add `set -g default-shell /bin/sh` to the shipped .tmux.conf. Per tmux's cmd-new-window.c, default-shell takes effect when default-command is empty (the default), so consumer test workspaces can still override default-shell per-session — for example tmuxp's window_options_after.yaml pins default-shell: /bin/bash to test Up-arrow shell history. Setting default-command here would short-circuit those overrides, so it is intentionally left at tmux's default - tests/test_pytest_plugin.py: add a regression test asserting that base-index 1 and default-shell /bin/sh appear in the generated config, and that default-command is intentionally absent
why: Commit 1 forced tmux's default-shell to /bin/sh in the test
config_file fixture, but $SHELL on the developer's machine still reports
/bin/zsh. Tests that compare os.getenv("SHELL") against the tmux pane's
running command — notably tmuxp's test_automatic_rename_option which
asserts `w.name in {pathlib.Path(os.getenv("SHELL")).name, ...}` — flake
because the pane runs sh while $SHELL says zsh.
A clear_env-only fix would not propagate to consumers like tmuxp whose
conftest does not consume libtmux's clear_env fixture. Pinning $SHELL
via an autouse fixture in the libtmux pytest plugin itself ensures every
plugin consumer's tests get the alignment without explicit opt-in.
what:
- pytest_plugin._pin_test_shell_env: new autouse function-scoped fixture
that runs `monkeypatch.setenv("SHELL", "/bin/sh")` before every test.
monkeypatch restores the prior value at teardown so no global state
leaks between processes
- pytest_plugin.clear_env: docstring updated to point at the new autouse
fixture; the SHELL handling moved out of clear_env so callers do not
need to opt into clear_env solely to get the alignment
- tests/test_pytest_plugin.py: regression test asserting
os.environ["SHELL"] == "/bin/sh" inside a test body, with no explicit
fixture opt-in (proves the autouse path)
why: With commit 1 hardcoding default-shell /bin/sh in the test config
and commit 2 forcing $SHELL=/bin/sh autouse, the entire USING_ZSH
apparatus is dead code. The zshrc fixture exists solely to suppress
zsh's first-run greeting that interfered with output capture — the new
config bypasses zsh entirely so the greeting never fires.
what:
- pytest_plugin.py: drop the module-level USING_ZSH constant and the
zshrc fixture (with its skipif decorator)
- conftest.py: drop the USING_ZSH import and the conditional
`if USING_ZSH: request.getfixturevalue("zshrc")` from setup_session.
Keep config_file as a setup_session arg so the .tmux.conf fixture
still materializes once per session (now with an explanatory docstring)
why: Three test sites used time.sleep to mask non-determinism that should be deterministic. With default-shell /bin/sh (commit 1) the zsh-prompt timing race that motivated some of these is gone, and libtmux ships retry_until in src/libtmux/test/retry.py for exactly this purpose. Sleeps mask flakiness while retry_until proves the condition; the latter is strictly better. what: - tests/test_server.py:test_new_session_shell_env: drop time.sleep(0.1) after new_session. The subsequent assertions (session_name, pane_start_command) read static properties populated synchronously by new_session — there's no race to mask. ruff auto-removed the now unused `import time` - tests/test_window.py:test_split_with_environment: replace time.sleep(0.05) with retry_until polling pane.capture_pane()[-2] for each expected env var output. retry_until's default 0.05s interval matches the original sleep but bounds the wait at 2s deterministic vs an arbitrary fixed delay. The pane uses a custom shell (env PS1='$ ' sh) so the global default-shell pin doesn't apply - tests/test_pytest_plugin.py:test_test_server_cleanup: replace time.sleep(0.1) "give time for cleanup" with retry_until polling server.is_alive() returning False. tmux's socket unlink is async; the poll catches it deterministically vs hoping 0.1s is enough
why: Commits 1-3 eliminated speculative time.sleep usage from the test
suite; without a guardrail, new contributors will reintroduce sleeps to
mask shell or fixture timing instead of using retry_until. Confirmed via
ruff's banned_api.rs source (crates/ruff_linter/src/rules/
flake8_tidy_imports/rules/banned_api.rs:59 banned_attribute_access) that
TID251 catches both `import time; time.sleep()` call sites and
`from time import sleep` imports. The TID251.py test fixture proves the
attribute-access path triggers exactly like our case.
what:
- pyproject.toml [tool.ruff.lint] select: add `TID` to enable
flake8-tidy-imports rules
- [tool.ruff.lint.flake8-tidy-imports.banned-api]: ban "time.sleep" with
a message pointing contributors at libtmux.test.retry.retry_until and
pane.wait_for_text as deterministic alternatives
- [tool.ruff.lint.per-file-ignores]:
- src/libtmux/test/retry.py exempted because it implements the helper
- tests/test/test_retry.py exempted because it tests the helper's
timing behavior and intentionally simulates slow operations
why: get_version() shells out to "tmux -V" via tmux_cmd. Plugin construction, has_gte_version() checks in capture_pane, and CLI startup all call it repeatedly within a single process. Profiling tmuxp's full test suite showed ~108 redundant fork+exec invocations of "tmux -V" per run — eliminating these trims real wall time on test suites and on production CLIs that resolve the version multiple times. what: - common.get_version: wrap with functools.lru_cache(maxsize=8) keyed by tmux_bin so repeat calls reuse the parsed LooseVersion. Errors are not cached; cache_clear() exposed for fixture resets - conftest.py: autouse fixture clears the cache around every test so monkeypatched tmux_cmd doublings in tests/test_common.py and tests/legacy_api/test_common.py do not leak synthetic versions into later tests - tests/test_common.py: add explicit regression test for the cache hit count and cache_clear() semantics; add cache_clear() before monkeypatched mocks so the fixture's pre-test state is irrelevant - tests/legacy_api/test_common.py: same defensive cache_clear() before each tmux_cmd-mocking test
tony
force-pushed
the
2026-04-perf-and-profiling
branch
2 times, most recently
from
November 30, 2026 01:42
7bd0d18 to
2b8a7c8
Compare
why: Pinning default-shell to /bin/sh uses dash on Ubuntu, where sh -c keeps sh as pane_current_command without exec and cooked-pty echo races initial prompt output when send_keys runs before shell readiness. what: - Use exec sleep 123 and retry_until in test_break_pane_no_name_uses_natural_name - Add tmux wait-for shell-readiness barriers to remaining automation_patterns.md and retry_until doctests
tony
force-pushed
the
2026-04-perf-and-profiling
branch
from
November 30, 2026 01:51
2b8a7c8 to
78d1f24
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Master through
v0.70.0rewrote the environment-test waits (test_new_session_shell_envandtest_split_with_environment) in #922 (0.68.0), raised the tmux floor to3.3ain #888 (0.65.0), and replacedmypywithty(uv run ty check) and RuffANNin #682 (0.70.0).Summary
Test suite is ~11% faster (45.22s → 39.63s on a clean run) and ~50-60% faster on consumers like tmuxp where per-pane shell init dominates. Adds a guardrail rule that prevents speculative
time.sleepcalls from sneaking back into tests.Seven commits, all engine-independent, all with regression tests where behavior changed.
What's in here
Faster, more deterministic test suite
Tmux pinned to
/bin/shin the test config fixture. Every test pane was spawning the developer's interactive shell (typically zsh) — ~60ms of init per pane, plus non-deterministic prompt rendering that flakedcapture-paneandautomatic-renameassertions. Nowdefault-shell /bin/shis set in the shipped.tmux.conffixture.default-commandis intentionally left empty so consumer test workspaces (e.g. tmuxp'swindow_options_after.yaml) can still overridedefault-shellper-session.\$SHELLenv var aligned to/bin/shvia autouse fixture. Tests that reados.getenv(\"SHELL\")(for example, comparing it to a tmux pane's running command) used to disagree with the actual tmux-spawned shell. The autouse fixture in libtmux's pytest plugin closes that gap for every plugin consumer — no opt-in required.USING_ZSHplumbing retired. With both shell pins in place, thezshrcfixture (which only ever existed to suppress zsh's first-run greeting) and theUSING_ZSHconstant are dead code. Removed cleanly.Three speculative
time.sleeptest sites replaced withretry_untilpolls.test_new_session_shell_env,test_split_with_environment,test_test_server_cleanupno longer mask non-determinism with fixed delays. They uselibtmux.test.retry.retry_until(already in the library) to poll until the actual condition is observed — proves correctness instead of hoping 0.05-0.1s is enough.Faster
get_version()get_version()is now memoized pertmux_binvalue via@functools.lru_cache(maxsize=8). Plugin construction,has_gte_version()checks incapture_pane, and CLI startup all called it repeatedly within a single process — measured ~108 redundanttmux -Vfork+exec calls per full test run. Errors are not cached (transient failures don't poison the lookup);cache_clear()is exposed for fixture resets.TID251 ruff rule bans
time.sleepin testsPairs with the
retry_untiladoption: now that the speculative sleeps are gone, the rule prevents new ones from being introduced. Per-file exemptions forsrc/libtmux/test/retry.py(implements the helper) andtests/test/test_retry.py(tests the helper's timing behavior).What this is not
get_version()signature unchanged.Server/Session/Window/Paneunchanged. The pytest plugin gains one autouse fixture (_pin_test_shell_env) that downstream consumers automatically benefit from.Verification
Linting passes:
```console
$ uv run ruff check .
```
Type-checking passes:
```console
$ uv run mypy
```
Test suite is green (888 passed = 885 previous + 3 new regression tests for shell-pin, autouse
\$SHELL, andget_versioncache-hit count):```console
$ uv run py.test --reruns 0
```
Docs build cleanly:
```console
$ just build-docs
```
Test plan