Skip to content

perf: lazily import public framework exports - #429

Merged
lesnik512 merged 2 commits into
mainfrom
perf/403-lazy-imports
Nov 4, 2026
Merged

lesnik512 merged 2 commits into
mainfrom
perf/403-lazy-imports

Conversation

@lesnik512

@lesnik512 lesnik512 commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Importing lite_bootstrap previously loaded all five framework bootstrappers, including unrelated frameworks installed in the environment. Resolve framework and Pyroscope exports lazily through module __getattr__, cache resolved names, and retain TYPE_CHECKING imports and __all__. Exceptions remain eager. __dir__ keeps all public exports discoverable without loading frameworks.

Closes #403.

Import timings

Python 3.14.7, local all-extras environment. Median elapsed import time across seven fresh processes per statement, with -X importtime enabled and timing measured inside each process:

Import Before After
import lite_bootstrap 680.95 ms 12.91 ms
from lite_bootstrap import FastAPIBootstrapper 677.70 ms 273.73 ms
from lite_bootstrap import ConfigurationError 730.97 ms 13.02 ms
from lite_bootstrap import PyroscopeConfig 681.73 ms 90.14 ms

Validation

  • Four subprocess isolation cases failed before the change and pass afterward.
  • A subprocess discovery regression failed before adding __dir__ and now confirms all public exports appear without importing any framework or changing sys.modules.
  • Every name in __all__ resolves in a fresh process; repeated access preserves identity and unknown names raise AttributeError.
  • just test-ci: 618 passed, 100% coverage.
  • just lint-ci: formatting, lint, and typechecking passed.
  • Standards and spec reviews found no issues.

Keep exceptions eager and load framework and Pyroscope exports on first access.
Preserve __all__ and TYPE_CHECKING imports. Subprocess isolation regressions
failed before the change and pass afterward.

Python 3.14.7, local all-extras environment, seven fresh processes per command
with -X importtime, median elapsed import time measured inside each process:
- import lite_bootstrap: 680.95 -> 12.91 ms
- from lite_bootstrap import FastAPIBootstrapper: 677.70 -> 273.73 ms
- from lite_bootstrap import ConfigurationError: 730.97 -> 13.02 ms
- from lite_bootstrap import PyroscopeConfig: 681.73 -> 90.14 ms

Validation: 617 tests passed, 100% coverage; lint and ty passed.
Standards and spec reviews found no issues.
@lesnik512
lesnik512 merged commit c3c0053 into main Nov 4, 2026
35 checks passed
@lesnik512
lesnik512 deleted the perf/403-lazy-imports branch November 4, 2026 10:06
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.

Import framework bootstrappers lazily from lite_bootstrap

1 participant