Skip to content

perf: reusable prepared statements for telemetry inserts#555

Open
Meet-hybrid wants to merge 1 commit into
StellarFlow-Network:mainfrom
Meet-hybrid:asset-optimization/prepared-statements
Open

perf: reusable prepared statements for telemetry inserts#555
Meet-hybrid wants to merge 1 commit into
StellarFlow-Network:mainfrom
Meet-hybrid:asset-optimization/prepared-statements

Conversation

@Meet-hybrid

Copy link
Copy Markdown

Create src/database/writer.py — a DatabaseWriter that pre-compiles INSERT statements once per (table, column-set) pair and reuses them across all batch writes, eliminating repeated SQL parsing overhead.

  • DatabaseWriter caches compiled INSERT SQL keyed by (table, *columns)
  • Uses psycopg2.sql.SQL + sql.Identifier for safe PostgreSQL composition
  • Uses executemany for both SQLite and PostgreSQL backends
  • Refactors BatchSink._flush to delegate to DatabaseWriter.insert_batch
  • Refactors LatencyTracker.flush to replace row-by-row cursor.execute with a single executemany call per flush cycle
  • All existing latency tracker tests pass (4/4)

Closes #482

Create src/database/writer.py — a DatabaseWriter that pre-compiles
INSERT statements once per (table, column-set) pair and reuses them
across all batch writes, eliminating repeated SQL parsing overhead.

- DatabaseWriter caches compiled INSERT SQL keyed by (table, *columns)
- Uses psycopg2.sql.SQL + sql.Identifier for safe PostgreSQL composition
- Uses executemany for both SQLite and PostgreSQL backends
- Refactors BatchSink._flush to delegate to DatabaseWriter.insert_batch
- Refactors LatencyTracker.flush to replace row-by-row cursor.execute
  with a single executemany call per flush cycle
- All existing latency tracker tests pass (4/4)
@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@Meet-hybrid Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

🗄️ Database-Pipeline | Reusable Prepared Statements for Telemetry Inserts

1 participant