Skip to content

perf(tui): cut render delay by deferring provider and memory - #157

Merged
cyfyifanchen merged 3 commits into
mainfrom
perf/lazy_provider
Jul 19, 2026
Merged

perf(tui): cut render delay by deferring provider and memory#157
cyfyifanchen merged 3 commits into
mainfrom
perf/lazy_provider

Conversation

@0xKT

@0xKT 0xKT commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Profiling raven tui bring-up put the agent-loop build
(_build_tui_agent_loop) at ~7s, so the TUI showed an empty shell
for several seconds before real content (issue #128 reports it as a
4-5s delay). Two eager imports on that path dominated: litellm when
the loop built its provider, and the everos/lancedb memory backend
(its start() measured ~2.5s). Deferring both off the render path
drops the build to ~1.8s -- the diffuse-import residual -- and a
startup loader fills what remains.

  • perf: LazyProvider defers litellm to the first chat (with a
    background prewarm); EverosBackend defers its adapter import into
    start(), which the TUI runs in the background after the render
    handshake. recall/store degrade to empty until the backend is ready.
    A cheap credential check keeps startup fail-fast without importing
    litellm.
  • feat(tui): a StartupLoader (braille spinner in the SessionPanel
    box) fills the pre-handshake gap and is replaced by the real panel
    the moment session.info arrives.

The empty-shell window drops from ~7s to ~1-2s, with real tool/skill
counts and no -32008 on the first send.

Non-blocking trade-offs (documented, not bugs): the residual ~1.8s is
diffuse imports with no single lever; quitting within the first ~2.5s
waits briefly on the background backend task; a first message sent
within ~2.5s runs one turn without memory recall (silent degrade).
Phase-timing startup logs (one of the issue's acceptance items) were
not added -- the delay was root-fixed rather than instrumented.

Also reformats useMainApp.ts (a pre-existing drift from #80) so the
whole-tree prettier hook passes on this first ui-tui change since.

Type

  • Fix
  • Feature

Verification

  • Relevant tests pass locally
  • Relevant lint / type checks pass locally

Commands: make lint-python, make test-python, and
cd ui-tui && npm run lint && npm run type-check && npm test && npm run build.

Risk

  • Backward compatibility considered

Provider swap on model change still works (the loop holds a plain
assignable provider attribute). agent/gateway paths keep make_provider;
only the TUI uses the lazy path.

Related Issues

Fixes #128

0xKT and others added 3 commits July 19, 2026 12:56
Building the agent loop eagerly imported litellm (~2-7s) and the
everos/lancedb memory backend (~2.1s) on the render path, so
`raven tui` showed an empty shell for 4-5s before real content.

- LazyProvider wraps the real provider so litellm loads on first
  chat, with a background prewarm thread; wired via make_lazy_provider
  for the TUI only. A cheap credential check preserves startup
  fail-fast without importing litellm.
- EverosBackend defers its adapter import into start(), which the TUI
  now runs in the background after the render handshake; recall and
  store degrade to empty until it is ready.

Render drops from 4-5s to ~1-2s with real tool and skill counts.

Co-authored-by: Claude (claude-opus-4-8) <noreply@anthropic.com>
The intro row rendered an empty body between the wordmark and the
session.info handshake (~1-2s). Show a StartupLoader in that gap: a
braille spinner in the same rounded box as SessionPanel, with a
label that steps through the bring-up stages. It is replaced by
SessionPanel the moment info arrives, so there is no residual height.

Co-authored-by: Claude (claude-opus-4-8) <noreply@anthropic.com>
The prettier-ui-tui hook checks the whole src tree on any ui-tui
change; `useMainApp.ts` carried a pre-existing drift from #80 that
this branch is the first ui-tui change to trip. Reformat it so CI is
green.

Co-authored-by: Claude (claude-opus-4-8) <noreply@anthropic.com>
@0xKT
0xKT requested a review from cyfyifanchen July 19, 2026 05:07
@cyfyifanchen
cyfyifanchen merged commit 81f72a3 into main Jul 19, 2026
8 checks passed
@cyfyifanchen
cyfyifanchen deleted the perf/lazy_provider branch July 19, 2026 05:49
@cyfyifanchen cyfyifanchen mentioned this pull request Jul 19, 2026
12 tasks
cyfyifanchen added a commit that referenced this pull request Jul 19, 2026
## Summary

Bump Raven package metadata from 0.1.5 to 0.1.6 so the release tag can
build a wheel from the current main branch.

This release carries the changes merged after v0.1.5:

- Version display now derives from installed package metadata (#139).
- Tracing dashboard port reuse avoids taking over non-Raven viewers
(#141).
- CLI startup defers LiteLLM imports for faster cold start (#147).
- Self-evolution stack and AppWorld benchmark entry points are included
(#140).
- TUI render delay is reduced by deferring provider and memory loading
(#157).

## Type

- [ ] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [x] Other

## Verification

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed

Commands run:

- `PYTHONPATH=. uv run pytest
tests/test_cli_smoke.py::test_version_flag_matches_installed_metadata
-q`
- `make check-commits COMMIT_RANGE=origin/main..HEAD`
- `PYTHONPATH=. uv run python scripts/check_commit_file.py
/tmp/raven-commit-msg.txt`

No user-facing docs or screenshots were needed for this version metadata
bump; release notes will be published with the GitHub Release.

## Risk

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

This changes package metadata only. Rollback is to delete the v0.1.6
tag/release if publication fails before users upgrade, or publish a
follow-up patch release if a released package issue is found.

## Related Issues

N/A
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.

perf(tui): investigate 4-5s delay before Raven renders

2 participants