Skip to content

App tests stop paying for imports, palette waits and settings resolves they never needed - #1592

Merged
trissim merged 3 commits into
mainfrom
test/app-tests-tick-at-1000fps
Nov 6, 2026
Merged

trissim merged 3 commits into
mainfrom
test/app-tests-tick-at-1000fps

Conversation

@trissim

@trissim trissim commented Nov 6, 2026

Copy link
Copy Markdown

Numbers first. A tiny app test in tests/textual/test_initial_session_title.py cost 1.43–1.98 s, and about 0.05 s of that was the test body. The rest was Toad booting. After this PR plus OpenHCSDev/textual#256 they cost 0.93–1.04 s each. The template's first test (its warm-up) went from 10.6 s to 6.2 s.

Measured with timestamps along one test's path (runner → fork → child pytest → app construct → run_test → start worker → session ready → body → teardown → reap):

step before
fork + child pytest collect 0.14 s
construct ToadApp 0.06 s
run_test until running 0.34–0.38 s
application start worker 0.13–0.18 s
first session ready 0.33–0.40 s
test body ~0.05 s
teardown 0.06 s

Commits

  1. Test apps publish frames every 1 ms (TEXTUAL_FPS=1000). Wheel walks no longer wait a 7 ms tick per event. Full tests/textual on 8 workers: 221 s against main's 231 s. Small (4%), kept.
  2. The test template imports every toad module before it forks. Each forked test imported the screens and widgets it mounted cold: 51 modules, 0.21 s cold. Importing them first also lets the template's schema warm-up cover Toad's own tables, so a child's ToadDatabase.prepare costs 4 ms instead of its cold build. Small tests: 1.43–1.98 s → 1.18–1.23 s.
  3. Saved settings resolve each level's owner once for its file keys. saved_key resolved the containing record's value per field (DeclaredField.owner_type → ObjectState.get_resolved_value) only to learn the owner class. One resolve per level now. Opening a populated toad.json: 48.0 ms → 13.7 ms at every launch. Keys held unchanged; settings, forms and keymap tests: 36 passed.

Paired change, outside this repository: OpenHCSDev/textual#256. HeadlessDriver waited out the full 0.25 s palette query (textual_colours.py:354) for replies to writes that go nowhere. With it, small tests are 0.93–1.04 s.

What more workers does not fix

On 12 workers the suite took 376 s, against 221 s on 8. Each test forks its own route observer and render workers, so 12 workers oversubscribe 12 cores. The lever is per-test cost, not worker count.

Still per test, next

  • Textual CSS parse: 0.077 s inside _prewarm_conversation_css. Stylesheets parse per app, and no module-level cache holds rule sets.
  • Compose and styling: about 0.5 s across ~300 widgets.
  • Main-thread idle: about 0.15 s waiting on the route observer's first pass over an empty bus root, the same cold pass as the launch first-paint stall.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XbFMSqJMarXn2ZE8iAL7Sd

trissim and others added 3 commits November 6, 2026 13:46
Each forked app test imported the screens and widgets it mounted cold (toad.screens.comms,
widgets.comms_chat, wire_history, welcome, session_tabs: 51 modules, 0.21 s cold), so every
one of 594 tests paid again for imports the template could hold once. Imported before the
fork, the smallest app tests in test_initial_session_title.py go from 1.43-1.98 s to
1.18-1.23 s each, and the template's own first test from 10.6 s to 6.2 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XbFMSqJMarXn2ZE8iAL7Sd
keys_held and kept asked saved_key for every setting, and saved_key resolved the containing
record's value (DeclaredField.owner_type -> ObjectState.get_resolved_value) per field, only to
learn which class owns the field's file key. Every field of one level shares that owner, so
saved_keys resolves it once and maps every field to its key. Opening settings at launch goes
from 48.0 ms to 13.7 ms for a populated toad.json (15.3 to 11.3 ms for an empty one); the
keys held are unchanged. tests/model/test_saved_settings.py and the settings, forms and
keymap tests: 36 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XbFMSqJMarXn2ZE8iAL7Sd
Copilot AI balanced review requested due to automatic review settings November 6, 2026 19:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@trissim
trissim enabled auto-merge November 6, 2026 19:02
@trissim
trissim merged commit 85506fe into main Nov 6, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants