Skip to content

feat: performance improvements#354

Draft
euri10 wants to merge 11 commits intolitestar-org:mainfrom
euri10:benchs
Draft

feat: performance improvements#354
euri10 wants to merge 11 commits intolitestar-org:mainfrom
euri10:benchs

Conversation

@euri10
Copy link
Collaborator

@euri10 euri10 commented Feb 2, 2026

wip, trying to figure out if reads are indeed weirdly slow

@euri10
Copy link
Collaborator Author

euri10 commented Feb 2, 2026

im wondering if the sqlalchemy write part does something it feels weird that it would be faster than the base driver

❯ python scripts/bench.py --driver asyncpg --driver sqlite
Running benchmark for driver: asyncpg
Running benchmark for driver: sqlite
                          Benchmark Results
┏━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓
┃ Driver  ┃ Library    ┃ Scenario       ┃ Time (s) ┃ % Slower vs Raw ┃
┡━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩
│ asyncpg │ raw        │ initialization │   0.0497 │               — │
│ asyncpg │ sqlspec    │ initialization │   0.0977 │           96.6% │
│ asyncpg │ sqlalchemy │ initialization │   0.0329 │          -33.7% │
│ asyncpg │ raw        │ write_heavy    │  51.8678 │               — │
│ asyncpg │ sqlspec    │ write_heavy    │  56.8252 │            9.6% │
│ asyncpg │ sqlalchemy │ write_heavy    │   4.5475 │          -91.2% │
│ asyncpg │ raw        │ read_heavy     │   0.0721 │               — │
│ asyncpg │ sqlspec    │ read_heavy     │   0.1858 │          157.8% │
│ asyncpg │ sqlalchemy │ read_heavy     │   0.1080 │           49.9% │
│ sqlite  │ raw        │ initialization │   0.0007 │               — │
│ sqlite  │ sqlspec    │ initialization │   0.0029 │          343.8% │
│ sqlite  │ sqlalchemy │ initialization │   0.0043 │          555.7% │
│ sqlite  │ raw        │ write_heavy    │   0.0594 │               — │
│ sqlite  │ sqlspec    │ write_heavy    │   2.5934 │         4269.5% │
│ sqlite  │ sqlalchemy │ write_heavy    │   0.7772 │         1209.4% │
│ sqlite  │ raw        │ read_heavy     │   0.0804 │               — │
│ sqlite  │ sqlspec    │ read_heavy     │   2.5633 │         3087.9% │
│ sqlite  │ sqlalchemy │ read_heavy     │   0.7890 │          881.2% │
└─────────┴────────────┴────────────────┴──────────┴─────────────────┘
Benchmarks complete for drivers: asyncpg, sqlite

@cofin cofin changed the title Benchs feat: performance improvements Feb 4, 2026
cofin pushed a commit that referenced this pull request Feb 4, 2026
Add comprehensive benchmark tooling originally contributed by euri10
in PR #354, with enhancements for testing query cache effectiveness.

Scenarios:
- initialization: Connection and table setup overhead
- write_heavy: Bulk insert performance (execute_many)
- read_heavy: Bulk read with fetchall
- repeated_queries: Single-row queries with varying params (tests _qc_*)

Compares: raw driver vs sqlspec vs SQLAlchemy
Drivers: sqlite (asyncpg requires PostgreSQL server)

Usage:
  uv run python scripts/bench.py --driver sqlite --rows 10000

Co-authored-by: euri10 <benoit.barthelet@gmail.com>
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