Skip to content

perf: split scalar/literal v2 types and declare __lazy_modules__ for Python 3.15 - #8

Merged
phil65 merged 1 commit into
mainfrom
perf/lazy-imports-and-v2-types
Nov 27, 2026
Merged

phil65 merged 1 commit into
mainfrom
perf/lazy-imports-and-v2-types

Conversation

@phil65

@phil65 phil65 commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Extracts all 161 pure scalar/Literal/Annotated[scalar, Field(...)] type aliases from the generated v2_protocol.py into a lightweight leaf module codexed.models.v2_types and declares PEP 810 __lazy_modules__ in the barrel __init__.py files.

Changes

  • Split 161 pure scalar/literal aliases into src/codexed/models/v2_types.py (22 KB, zero BaseModels, zero mcp imports) and import them back into v2_protocol.py.
  • Wire schemez.split_scalar_type_aliases (from feat(code_generation): add split_scalar_type_aliases helper schemez#16) into scripts/generate_codex_reference_models.py and add schemez to the dev dependency group so future schema regenerations keep v2_types.py in sync automatically.
  • Add PEP 810 __lazy_modules__ to codexed/__init__.py, codexed/models/__init__.py, and codexed/client/__init__.py, re-exporting scalar/literal aliases directly from codexed.models.v2_types / codexed.models.codex_types.
  • Add tests/test_lazy_imports.py verifying all public exports resolve and that importing Personality/ReasoningEffort/SandboxMode on Python 3.15+ does not load v2_protocol, codexed.client, or mcp.

Python 3.15.2 cold import benchmarks (warm .pyc, 3-run median)

Import Before After Speedup
import codexed ~744–863 ms ~23 ms ~35×
from codexed import Personality, ReasoningEffort, SandboxMode ~723–907 ms ~64 ms (incl. cold pydantic; <5 ms when pydantic is already loaded) ~12×

@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.12%. Comparing base (e1975d9) to head (fb49d7e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main       #8      +/-   ##
==========================================
+ Coverage   90.11%   90.12%   +0.01%     
==========================================
  Files          28       29       +1     
  Lines        6261     6271      +10     
==========================================
+ Hits         5642     5652      +10     
  Misses        619      619              

☔ 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.

@phil65
phil65 merged commit a152457 into main Nov 27, 2026
16 of 22 checks passed
@phil65
phil65 deleted the perf/lazy-imports-and-v2-types branch November 27, 2026 23:38
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.

1 participant