Skip to content

PERF: Lazily load all package exports - #2456

Open
Richard Lundeen (rlundeen2) wants to merge 8 commits into
microsoft:mainfrom
rlundeen2:rlundeen2-all-package-lazy-imports
Open

PERF: Lazily load all package exports#2456
Richard Lundeen (rlundeen2) wants to merge 8 commits into
microsoft:mainfrom
rlundeen2:rlundeen2-all-package-lazy-imports

Conversation

@rlundeen2

Copy link
Copy Markdown
Contributor

Summary

This is the second PR in a two-PR change stack. It is stacked on #2455; both head branches are in rlundeen2/PyRIT and target upstream main.

  • migrate remaining exported pyrit/**/__init__.py packages to the shared PEP 562 lazy-export contract
  • preserve package APIs, aliases, object identity, transformer warning suppression, and show_versions compatibility
  • explicitly materialize dataset and scenario catalogs only when complete discovery is requested
  • retain the intentional GCG experimental-warning import side effect

Cold start performance

Cold Start Benchmark Before Change After Change Faster
Text matching scorers 7.654465s 6.115633s 20.1%
ROT13/Base64/Base2048 converters 4.986345s 0.562701s 88.7%
import pyrit.memory 5.448382s 0.094392s 98.3%
import pyrit.datasets 8.121517s 0.094086s 98.8%

Each result is the median of seven fresh-process runs.

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
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
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@rlundeen2
Richard Lundeen (rlundeen2) force-pushed the rlundeen2-all-package-lazy-imports branch from c0ee34e to ed6a298 Compare August 21, 2026 17:15
Comment thread pyrit/__init__.py
Comment thread pyrit/analytics/__init__.py
Comment thread pyrit/scenario/scenarios/_dynamic_techniques.py
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ecd050f4-5e40-4f24-9d8f-8bf99736b9cd
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ecd050f4-5e40-4f24-9d8f-8bf99736b9cd
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ecd050f4-5e40-4f24-9d8f-8bf99736b9cd
Copilot-Session: ecd050f4-5e40-4f24-9d8f-8bf99736b9cd
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