Skip to content

perf(ui): build info popovers on first click -- tag editor 41% faster - #1557

Closed
dexhunter wants to merge 1 commit into
TagStudioDev:mainfrom
dexhunter:perf/lazy-info-popovers
Closed

dexhunter wants to merge 1 commit into
TagStudioDev:mainfrom
dexhunter:perf/lazy-info-popovers

Conversation

@dexhunter

Copy link
Copy Markdown

TL;DR

  • This PR makes the "Edit Tag" panel open faster by changing EditTagPanelView and InfoButton.
  • The two ⓘ info popovers are now built when the user first opens them, not when the panel opens.
  • Median time of 60 panel builds for a new tag: 36.35 ms -> 21.41 ms, 41.1% faster.
  • Tests: pytest tests gives 315 passed, and ruff and pyright are clean on both changed files.

What & Why

Before this change, the panel built both info popovers (ParentTagsInfoView and CategoriesInfoView) during construction. Each popover has many widgets, tag capsules, stylesheets and SVG icons. The popovers stay hidden until the user clicks an ⓘ button, so most panels never show them.

Now _title_row gives InfoButton the popover class, not a finished layout. InfoButton keeps it and builds the popover frame, content and fade effect in _build_popover on the first click. Later clicks reuse the same popover. The popover code itself does not change, so it looks the same when it opens.

Changes

  • InfoButton.__init__ accepts a layout or a function that returns a layout. Existing callers that pass a layout keep working.
  • The popover setup moves into a new _build_popover method, which _toggle_popover calls once.
  • EditTagPanelView._title_row passes ParentTagsInfoView and CategoriesInfoView as classes.

Results

Median time per call on Linux x86_64 with offscreen Qt. Each value is the median of 60 calls, taken as the middle value over 3 alternating runs of the old and new code.

Situation Before After Change
Open panel for a new tag (EditTagPanel(lib, None), as in the repo test) 36.35 ms 21.41 ms 41.1% faster
Open panel for an existing tag with a parent tag 42.64 ms 26.94 ms 36.8% faster
Open panel, then open and close both info popovers 50.46 ms 48.35 ms 4.2% faster, no slowdown

The last row shows the cost does not grow when the user opens the popovers. The work only moves to the first click.

Why this is safe and easy to maintain

The change is small, and the popover setup code moves into one method without a copy. The panel layout, the popover content and the popover position stay the same. tests/qt/test_edit_tag_panel.py and the rest of the Qt test suite cover the panel. A separate check also compared the full widget tree and the rendered panel and popover images against the old code.

Validation

  • QT_QPA_PLATFORM=offscreen pytest tests gives 315 passed and 1 snapshot passed.
  • ruff check and ruff format --check (0.15.17) pass on both files, and pyright reports 0 errors.
  • To reproduce the timing, build the panel in a loop with the library from tests/conftest.py:
t = time.perf_counter(); panel = EditTagPanel(library, None); dt = time.perf_counter() - t

Tasks Completed

  • Platforms Tested:
    • Windows x86
    • Windows ARM
    • macOS x86
    • macOS ARM
    • Linux x86 (automated tests with offscreen Qt only)
    • Linux ARM
  • Tested For:
    • Basic functionality
    • PyInstaller executable

AI assistance

OpenAI Codex (gpt-6.1-sol) generated the code change as candidates, and Weco Observe tracked them. Claude Code picked this candidate and ran the tests and timings. Automated checks compared the output with the old code. No manual run of the app was done.

Weco share link: https://dashboard.weco.ai/share/Uj5APINlfofYXq95xoryZnOa5KJ94bGY

EditTagPanelView built both info popovers (ParentTagsInfoView and
CategoriesInfoView) on every panel construction, although they stay
hidden until the user clicks an info button. InfoButton now also accepts
a function that returns the popover layout and builds the popover on the
first click. Passing a layout keeps working.

Building the edit tag panel for a new tag drops from 36.35 ms to
21.41 ms (median of 60). The popover content and the panel layout do
not change.

Co-Authored-By: Aiden <aiden@weco.ai>
@xarvex xarvex closed this Nov 6, 2026
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