Skip to content

Super speed up the UI diagram prep - #1212

Open
TimMonko wants to merge 1 commit into
napari:mainfrom
TimMonko:ui-sections-speed
Open

TimMonko wants to merge 1 commit into
napari:mainfrom
TimMonko:ui-sections-speed

Conversation

@TimMonko

@TimMonko TimMonko commented Nov 6, 2026

Copy link
Copy Markdown
Member

References and relevant issues

Part of #1209, found by profiling with #1204

Description

prep_docs.py generates the UI architecture pages with pydeps and this step has been known to be superrr slow (part of @psobolewskiPhD's motivation for the slim builds). In CI, this step takes 350s of the whole 940s build docs step (it takes 480s for me locally).

For each of the 7 sections, pydeps walked every import from the section's module, recursively, through the whole environment.
(via LLM: For the status bar section alone that is 10,834 modules: torch (2,192), sympy, scipy, pandas, numba, networkx, … and only about 640 napari modules.)
The --only napari... filter that keeps just the napari modules is applied to the finished graph, so its wasted work.

The pydeps module finder accepts excludes to stop it from investigating an import. The4 script now adds every top-level module that can't lead back to napari as an exclude. The output stays exactly the same because:

  1. Packages that import napari are still analyzed. napari_plugin_manager and npe2.io_utils import napari modules, so napari modules can be reached through them (napari._qt.qthreading in the Application menus page comes in that way). Anything named napari* and npe2, is kept, but we should probably use this as an opportunity to investigate some likely problematic import patterns too.
  2. Some napari modules are imported with relative imports, so pydeps tries to exclude stdlib modules like signal. This results in dropping the vendored qt_jsonschema_form.widgets -> qt_jsonschema_form.signal edge in the Dialogs page. The script has extra logic to keep any names that napari uses for its own modules.

Results

before, locally: 480s
AFTER: TWELVE (12!) SECONDS!!!!!!!!!!!!!!!

So, hopefully CI also drops by ~340s (ALMOST 6 MINUTES!!!!!!).

A 30% decrease in total build time!!!!!!!!!

pydeps statically follows every import from each UI section's module,
including into numpy, scipy, torch, sympy and the rest of the
environment: over 10,000 modules per section, of which ~640 are napari.
The `--only` filter that keeps just the napari modules is only applied
afterwards, so each of the 7 sections spent 50-150 s in that analysis.

Pass every top-level module that can't lead back to napari as an
exclude, so the module finder never enters it. Packages that import
napari modules (napari_*, and npe2.io_utils) are still analyzed, and
names that napari also uses for its own modules (e.g. a local
`signal.py`) are never excluded, because pydeps matches the bare name
of relative imports against the excludes.

The UI sections step goes from 482 s to 12 s, and all 7 generated
pages are byte-identical to before.
@TimMonko TimMonko added this to the 0.11.0 milestone Nov 6, 2026
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

@TimMonko

TimMonko commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

@napari-bot make html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant