Skip to content

Commit dc3857e

Browse files
authored
feat: improve mypyc configurations (#388)
Continue optimizations to Mypyc compilation layer
1 parent fc24a72 commit dc3857e

189 files changed

Lines changed: 6012 additions & 3040 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
- id: mixed-line-ending
1818
- id: trailing-whitespace
1919
- repo: https://github.com/charliermarsh/ruff-pre-commit
20-
rev: "v0.15.5"
20+
rev: "v0.15.6"
2121
hooks:
2222
- id: ruff
2323
args: ["--fix"]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ pgo-local: ## Run full three-stage PGO
365365
@echo "${OK} Instrumented wheel built"
366366
@echo "${INFO} Stage 2: Running training workload..."
367367
@uv pip install dist/*.whl --force-reinstall --no-deps >/dev/null 2>&1
368-
@.venv/bin/python -m sqlspec._pgo_training
368+
@.venv/bin/python tools/scripts/pgo_training.py
369369
@echo "${OK} Training complete"
370370
@rm -rf dist/ $(PGO_BUILD_DIR)/build $(PGO_BUILD_DIR)/tmp
371371
@echo "${INFO} Stage 3: Building PGO-optimized wheel..."

performance_surface_inventory.json

Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
{
2+
"task_id": "sqlspec-iab.6.1",
3+
"captured_on": "2026-03-14",
4+
"summary": {
5+
"adapter_count": 16,
6+
"bench_harness_driver_count": 4,
7+
"regression_gate_driver_count": 1
8+
},
9+
"benchmark_scripts": {
10+
"bench.py": {
11+
"drivers": [
12+
"aiosqlite",
13+
"asyncpg",
14+
"duckdb",
15+
"sqlite"
16+
],
17+
"core_scenarios": [
18+
"initialization",
19+
"write_heavy",
20+
"read_heavy",
21+
"iterative_inserts",
22+
"repeated_queries"
23+
],
24+
"extended_scenarios": [
25+
"dict_key_transform",
26+
"schema_mapping",
27+
"complex_parameters",
28+
"thin_path_stress"
29+
]
30+
},
31+
"bench_gate.py": {
32+
"drivers": [
33+
"sqlite"
34+
],
35+
"gate_scenarios": [
36+
"iterative_inserts",
37+
"repeated_queries",
38+
"write_heavy",
39+
"read_heavy"
40+
]
41+
},
42+
"bench_subsystems.py": {
43+
"drivers": [
44+
"sqlite"
45+
],
46+
"focus_areas": [
47+
"SQL object construction",
48+
"SQL.compile()",
49+
"query-cache prepare/lookup",
50+
"parameter processing",
51+
"cursor lifecycle",
52+
"storage/runtime helpers"
53+
]
54+
}
55+
},
56+
"build_workflows": {
57+
"publish.yml": {
58+
"tier": "release",
59+
"builds_mypyc_wheels": true,
60+
"exercises_three_stage_pgo": true,
61+
"uses_packaged_training_module": true,
62+
"notes": "Release wheels still run `python -m sqlspec._pgo_training` during the three-stage PGO flow."
63+
},
64+
"test-build.yml": {
65+
"tier": "pull_request/workflow_dispatch",
66+
"builds_mypyc_wheels": true,
67+
"exercises_three_stage_pgo": false,
68+
"uses_packaged_training_module": false,
69+
"notes": "PR build validation compiles mypyc wheels but does not run reduced three-stage PGO parity."
70+
}
71+
},
72+
"external_infra": {
73+
"dma_accelerator": {
74+
"reusable_lifecycle_modules": [
75+
"postgres",
76+
"mysql",
77+
"oracle",
78+
"sqlserver"
79+
],
80+
"root_cli_registered_families": [
81+
"postgres"
82+
],
83+
"notes": "Reusable lifecycle code exists for PostgreSQL, MySQL, Oracle, and SQL Server, but the root CLI currently mounts only PostgreSQL. MySQL and Oracle still need SQLSpec-facing exposure work before they can be treated as directly reusable perf infrastructure."
84+
}
85+
},
86+
"adapters": [
87+
{
88+
"name": "adbc",
89+
"execution_surfaces": [
90+
"sync"
91+
],
92+
"config_surface": "sqlspec/adapters/adbc/config.py",
93+
"integration_root": "tests/integration/adapters/adbc",
94+
"current_infra_family": "bridge/underlying-engine",
95+
"bench_harness_driver": false,
96+
"regression_gate_driver": false,
97+
"notes": "Integration coverage spans PostgreSQL, SQLite, and DuckDB backends, but no dedicated perf-harness workload exists yet."
98+
},
99+
{
100+
"name": "aiosqlite",
101+
"execution_surfaces": [
102+
"async"
103+
],
104+
"config_surface": "sqlspec/adapters/aiosqlite/config.py",
105+
"integration_root": "tests/integration/adapters/aiosqlite",
106+
"current_infra_family": "file-local",
107+
"bench_harness_driver": true,
108+
"regression_gate_driver": false,
109+
"notes": "Covered in bench.py, but not in bench_gate.py or bench_subsystems.py."
110+
},
111+
{
112+
"name": "asyncmy",
113+
"execution_surfaces": [
114+
"async"
115+
],
116+
"config_surface": "sqlspec/adapters/asyncmy/config.py",
117+
"integration_root": "tests/integration/adapters/asyncmy",
118+
"current_infra_family": "server-backed",
119+
"bench_harness_driver": false,
120+
"regression_gate_driver": false,
121+
"notes": "MySQL-family integration coverage exists, but there is no current perf-harness workload."
122+
},
123+
{
124+
"name": "asyncpg",
125+
"execution_surfaces": [
126+
"async"
127+
],
128+
"config_surface": "sqlspec/adapters/asyncpg/config.py",
129+
"integration_root": "tests/integration/adapters/asyncpg",
130+
"current_infra_family": "server-backed",
131+
"bench_harness_driver": true,
132+
"regression_gate_driver": false,
133+
"notes": "Bench coverage exists in bench.py, but the regression gate remains SQLite-only."
134+
},
135+
{
136+
"name": "bigquery",
137+
"execution_surfaces": [
138+
"sync"
139+
],
140+
"config_surface": "sqlspec/adapters/bigquery/config.py",
141+
"integration_root": "tests/integration/adapters/bigquery",
142+
"current_infra_family": "cloud-managed",
143+
"bench_harness_driver": false,
144+
"regression_gate_driver": false,
145+
"notes": "Integration coverage exists, but there is no current perf or build-path matrix entry for the adapter."
146+
},
147+
{
148+
"name": "cockroach_asyncpg",
149+
"execution_surfaces": [
150+
"async"
151+
],
152+
"config_surface": "sqlspec/adapters/cockroach_asyncpg/config.py",
153+
"integration_root": "tests/integration/adapters/cockroach_asyncpg",
154+
"current_infra_family": "server-backed",
155+
"bench_harness_driver": false,
156+
"regression_gate_driver": false,
157+
"notes": "Cockroach async coverage exists in integration tests only."
158+
},
159+
{
160+
"name": "cockroach_psycopg",
161+
"execution_surfaces": [
162+
"sync",
163+
"async"
164+
],
165+
"config_surface": "sqlspec/adapters/cockroach_psycopg/config.py",
166+
"integration_root": "tests/integration/adapters/cockroach_psycopg",
167+
"current_infra_family": "server-backed",
168+
"bench_harness_driver": false,
169+
"regression_gate_driver": false,
170+
"notes": "Cockroach psycopg integration coverage exists, but no perf harness tracks either sync or async surfaces."
171+
},
172+
{
173+
"name": "duckdb",
174+
"execution_surfaces": [
175+
"sync"
176+
],
177+
"config_surface": "sqlspec/adapters/duckdb/config.py",
178+
"integration_root": "tests/integration/adapters/duckdb",
179+
"current_infra_family": "file-local",
180+
"bench_harness_driver": true,
181+
"regression_gate_driver": false,
182+
"notes": "Bench coverage exists in bench.py, but no driver-specific gate or subsystem micro-benchmark exists."
183+
},
184+
{
185+
"name": "mock",
186+
"execution_surfaces": [
187+
"sync",
188+
"async"
189+
],
190+
"config_surface": "sqlspec/adapters/mock/config.py",
191+
"integration_root": null,
192+
"current_infra_family": "mock-only",
193+
"bench_harness_driver": false,
194+
"regression_gate_driver": false,
195+
"notes": "Useful for isolated behavior tests, but not a real performance validation surface."
196+
},
197+
{
198+
"name": "mysqlconnector",
199+
"execution_surfaces": [
200+
"sync",
201+
"async"
202+
],
203+
"config_surface": "sqlspec/adapters/mysqlconnector/config.py",
204+
"integration_root": "tests/integration/adapters/mysqlconnector",
205+
"current_infra_family": "server-backed",
206+
"bench_harness_driver": false,
207+
"regression_gate_driver": false,
208+
"notes": "Integration coverage exists for sync and async paths, but the perf harness does not exercise them yet."
209+
},
210+
{
211+
"name": "oracledb",
212+
"execution_surfaces": [
213+
"sync",
214+
"async"
215+
],
216+
"config_surface": "sqlspec/adapters/oracledb/config.py",
217+
"integration_root": "tests/integration/adapters/oracledb",
218+
"current_infra_family": "server-backed",
219+
"bench_harness_driver": false,
220+
"regression_gate_driver": false,
221+
"notes": "Integration coverage exists for sync and async Oracle paths, but there is no Oracle perf workload in the harness."
222+
},
223+
{
224+
"name": "psqlpy",
225+
"execution_surfaces": [
226+
"async"
227+
],
228+
"config_surface": "sqlspec/adapters/psqlpy/config.py",
229+
"integration_root": "tests/integration/adapters/psqlpy",
230+
"current_infra_family": "server-backed",
231+
"bench_harness_driver": false,
232+
"regression_gate_driver": false,
233+
"notes": "Integration coverage exists, but the current perf harness does not represent the adapter."
234+
},
235+
{
236+
"name": "psycopg",
237+
"execution_surfaces": [
238+
"sync",
239+
"async"
240+
],
241+
"config_surface": "sqlspec/adapters/psycopg/config.py",
242+
"integration_root": "tests/integration/adapters/psycopg",
243+
"current_infra_family": "server-backed",
244+
"bench_harness_driver": false,
245+
"regression_gate_driver": false,
246+
"notes": "Integration coverage exists for sync and async psycopg paths, but the perf harness still skips them."
247+
},
248+
{
249+
"name": "pymysql",
250+
"execution_surfaces": [
251+
"sync"
252+
],
253+
"config_surface": "sqlspec/adapters/pymysql/config.py",
254+
"integration_root": "tests/integration/adapters/pymysql",
255+
"current_infra_family": "server-backed",
256+
"bench_harness_driver": false,
257+
"regression_gate_driver": false,
258+
"notes": "Integration coverage exists, but no current perf workload or gate covers the adapter."
259+
},
260+
{
261+
"name": "spanner",
262+
"execution_surfaces": [
263+
"sync"
264+
],
265+
"config_surface": "sqlspec/adapters/spanner/config.py",
266+
"integration_root": "tests/integration/adapters/spanner",
267+
"current_infra_family": "cloud-managed",
268+
"bench_harness_driver": false,
269+
"regression_gate_driver": false,
270+
"notes": "Integration coverage exists, but cloud-managed validation is not represented in the current perf harness."
271+
},
272+
{
273+
"name": "sqlite",
274+
"execution_surfaces": [
275+
"sync"
276+
],
277+
"config_surface": "sqlspec/adapters/sqlite/config.py",
278+
"integration_root": "tests/integration/adapters/sqlite",
279+
"current_infra_family": "file-local",
280+
"bench_harness_driver": true,
281+
"regression_gate_driver": true,
282+
"notes": "SQLite is the only adapter covered by bench.py, bench_gate.py, and bench_subsystems.py."
283+
}
284+
]
285+
}

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ exclude = [
199199
"sqlspec/adapters/**/data_dictionary.py", # Cross-module inheritance causes mypyc segfaults
200200
"sqlspec/observability/_formatting.py", # Inherits from non-compiled logging.Formatter
201201
"sqlspec/utils/arrow_helpers.py", # Arrow operations cause segfaults when compiled
202-
"sqlspec/utils/profiling.py", # Uses sys.setprofile (dynamic, not mypyc compatible)
203-
"sqlspec/_pgo_training.py", # PGO training script — runs against compiled modules
202+
"sqlspec/storage/backends/_iterators.py", # Async __anext__ + asyncio.to_thread causes mypyc segfault
204203
]
205204
include = [
206205
"sqlspec/core/**/*.py", # Core module
@@ -209,6 +208,9 @@ include = [
209208
"sqlspec/loader.py", # Loader module
210209
"sqlspec/observability/**/*.py", # Observability utilities
211210
"sqlspec/driver/**/*.py", # Driver module
211+
"sqlspec/storage/registry.py", # Safe storage registry/runtime routing
212+
"sqlspec/storage/errors.py", # Safe storage error normalization
213+
"sqlspec/storage/backends/base.py", # Storage backend runtime base classes (iterators in _iterators.py)
212214
"sqlspec/data_dictionary/**/*.py", # Data dictionary mixin (required for adapter inheritance)
213215
"sqlspec/adapters/**/core.py", # Adapter compiled helpers
214216
"sqlspec/adapters/**/type_converter.py", # All adapters type converters

sqlspec/_serialization.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,30 @@
1111
import datetime
1212
import enum
1313
import json
14+
import uuid as _uuid_mod
1415
from abc import ABC, abstractmethod
1516
from decimal import Decimal
1617
from typing import Any, Final, Literal, Protocol, overload
1718

18-
from sqlspec._typing import NUMPY_INSTALLED
19+
from sqlspec._typing import NUMPY_INSTALLED, UUID_UTILS_INSTALLED
1920
from sqlspec.core.filters import OffsetPagination
2021
from sqlspec.typing import MSGSPEC_INSTALLED, ORJSON_INSTALLED, PYDANTIC_INSTALLED, BaseModel
2122

2223

24+
def _get_uuid_utils_type() -> "type[Any] | None":
25+
if not UUID_UTILS_INSTALLED:
26+
return None
27+
try:
28+
import uuid_utils as _uuid_utils_mod # pyright: ignore[reportMissingImports]
29+
except ImportError:
30+
return None
31+
else:
32+
return _uuid_utils_mod.UUID # type: ignore[no-any-return,unused-ignore]
33+
34+
35+
_UUID_UTILS_TYPE: "type[Any] | None" = _get_uuid_utils_type()
36+
37+
2338
def _type_to_string(value: Any) -> Any: # pragma: no cover
2439
"""Convert special types to strings for JSON serialization.
2540
@@ -44,6 +59,10 @@ def _type_to_string(value: Any) -> Any: # pragma: no cover
4459
return str(value.value)
4560
if PYDANTIC_INSTALLED and isinstance(value, BaseModel):
4661
return value.model_dump_json()
62+
if isinstance(value, _uuid_mod.UUID):
63+
return str(value)
64+
if _UUID_UTILS_TYPE is not None and isinstance(value, _UUID_UTILS_TYPE):
65+
return str(value)
4766
if isinstance(value, OffsetPagination):
4867
return {"items": value.items, "limit": value.limit, "offset": value.offset, "total": value.total}
4968
if NUMPY_INSTALLED:

0 commit comments

Comments
 (0)