Skip to content

PERF: Lazily load exports infrastructure - #2455

Merged
Richard Lundeen (rlundeen2) merged 2 commits into
microsoft:mainfrom
rlundeen2:rlundeen2-speed-pyrit-cold-start
Aug 22, 2026
Merged

PERF: Lazily load exports infrastructure#2455
Richard Lundeen (rlundeen2) merged 2 commits into
microsoft:mainfrom
rlundeen2:rlundeen2-speed-pyrit-cold-start

Conversation

@rlundeen2

@rlundeen2 Richard Lundeen (rlundeen2) commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Description

This is the first PR in a two-PR change stack. Follow-up: #2456.

Add a shared PEP 562 lazy-import helper that resolves and caches package exports on first access while exposing unresolved names through dir().

Migrate all public pyrit.models package exports to this contract. _LAZY_EXPORTS is the runtime source of truth, __all__ derives from it, and TYPE_CHECKING imports preserve editor and static-analysis support. Existing named imports and object identity remain compatible.

Add focused helper tests and a repository-wide package contract test. The contract test discovers every package initializer, validates migrated packages, spot-checks model imports, and maintains an exact exception ratchet for packages that remain eager.

Tests and Documentation

  • python -m pytest -q tests\unit\common tests\unit\models — 1,426 passed
  • SKIP=ty-check python -m pre_commit run --all-files — passed
  • The standalone ty-check hook was stopped after it stalled in the local environment.
  • No documentation changes were required for this internal import-loading change.

Defer model re-exports until first access and add a repository-wide lazy package contract test with a ratcheting eager-package exception list.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: d2bd1e1d-bef9-454a-b04a-be5fde48fcab
@rlundeen2 Richard Lundeen (rlundeen2) changed the title PERF: Lazily load model package exports PERF: Lazily load exports infrastructure Aug 21, 2026
Exercise model package dir hooks and export resolution in the coverage process so diff coverage includes the PEP 562 contract.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: d2bd1e1d-bef9-454a-b04a-be5fde48fcab

@romanlutz Roman Lutz (romanlutz) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very interesting!

@rlundeen2
Richard Lundeen (rlundeen2) added this pull request to the merge queue Aug 22, 2026
Merged via the queue into microsoft:main with commit c5e1c39 Aug 22, 2026
54 checks passed
@rlundeen2
Richard Lundeen (rlundeen2) deleted the rlundeen2-speed-pyrit-cold-start branch August 22, 2026 03:22
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