8000 perf: public names load on first use, import flahax 350 ms to 2.5 ms by rafatahmed · Pull Request #336 · rafatahmed/Flahax · GitHub
[go: up one dir, main page]

Skip to content

perf: public names load on first use, import flahax 350 ms to 2.5 ms - #336

Merged
rafatahmed merged 2 commits into
mainfrom
perf/lazy-imports
Nov 26, 2026
Merged

rafatahmed merged 2 commits into
mainfrom
perf/lazy-imports

Conversation

@rafatahmed
Copy link
Copy Markdown
Owner

Closes #335

import flahax loaded all 60 modules (about 350 ms). Public names now resolve on first use (PEP 562), so a bare import loads no submodule (2.5 ms). A name loads only the module that defines it. __all__, from flahax import X and flahax.<submodule> behave as before.

  • material_chemistry and phase_allocation are both a function and a submodule. A small module class stops a submodule import from replacing the function, in any import order (tested).
  • Ruff F822 is ignored for src/flahax/__init__.py only, since the names are no longer visible statically.
  • New tests/test_lazy_imports.py: bare import loads nothing, every __all__ name resolves to the defining object, shadowed names survive any import order, unknown names raise AttributeError.

Evidence

Records in outputs/test-runs/2026-11-26-perf-lazy-imports/SUMMARY.md (local, not committed).

  • 215 of 224 test modules pass; 9 heavy modules were rerun test by test: 175 of 181 pass.
  • Not verified: 6 solver tests that take about 250 s each alone (ratio_allocation_reliability, two ratio_search_constraints). They did not fit the 5-minute run limit; CI will run them.
  • test_file_headers fails the same 434 cases on main in my Windows checkout (shebang/CRLF), unrelated.
  • No chemistry code changed, so no PHREEQC fixture re-capture applies.
  • Still slow after this: recommend costs about 110 ms on first call because engine imports the catalogue chain; a follow-up.

@rafatahmed rafatahmed added the enhancement New feature or request label Nov 26, 2026
@rafatahmed rafatahmed self-assigned this Nov 26, 2026
@codecov
codecov Bot commented Nov 26, 2026
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (fd34197) to head (9483919).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #336   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          148       148           
  Lines        17466     17446   -20     
  Branches      3539      3542    +3     
=========================================
- Hits         17466     17446   -20     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rafatahmed
rafatahmed marked this pull request as ready for review November 26, 2026 20:46
@rafatahmed
rafatahmed merged commit 906d29b into main Nov 26, 2026
29 checks passed
9164
@rafatahmed
rafatahmed deleted the perf/lazy-imports branch November 26, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: import flahax takes ~350 ms because all 60 modules load eagerly

1 participant

0