Skip to content

Core Architecture Refactor: Enum Dispatch, Zero-Allocation Rows & Workspace Migration#46

Merged
Einswilli merged 303 commits into
AllDotPy:masterfrom
Einswilli:new_design
May 9, 2026
Merged

Core Architecture Refactor: Enum Dispatch, Zero-Allocation Rows & Workspace Migration#46
Einswilli merged 303 commits into
AllDotPy:masterfrom
Einswilli:new_design

Conversation

@Einswilli
Copy link
Copy Markdown
Contributor

Summary

This PR implements a major architectural overhaul of Ryx to move from a dynamic, sqlx::Any-based system to a high-performance, statically dispatched architecture. The primary goal is to minimize latency in the hot path (ORM and Raw Core) by eliminating vtable lookups and reducing heap allocations during data retrieval.

Key Changes

🏗️ Architecture & Project Structure

  • Workspace Migration: Restructured the project into a Rust workspace with specialized crates to isolate responsibilities and improve compile times:
    • ryx-core: Base types, errors, and the new unified type system.
    • ryx-backend: Database-specific implementations and connection management.
    • ryx-python: PyO3 bindings and Python-facing logic.
    • ryx-query: SQL AST and compilation logic.

⚡ Performance Optimizations

  • Static Dispatch (Enum-based): Replaced dyn RyxBackend and sqlx::Any with RyxConnection and RyxTransaction enums. This allows the compiler to inline backend-specific code and removes the overhead of dynamic dispatch.
  • Zero-Allocation Row Architecture:
    • Replaced the per-row HashMap<String, SqlValue> with a RowView (a Vec of values referencing a shared RowMapping).
    • This eliminates thousands of small allocations per result set and significantly reduces memory fragmentation.
  • FFI Boundary Optimization: Optimized the Python $\rightarrow$ Rust type conversion in py_to_sql_value by using type_ptr() comparisons instead of a trial-and-error casting cascade.

🛠️ Transaction & Connection Management

  • Implemented a unified RyxExecutor trait for raw query execution.
  • Updated the transaction system to use the new enum types, ensuring type safety across the PyO3 boundary while maintaining a unique PyTransactionHandle.

Performance Impact

  • Latency: Significant reduction in overhead for every query execution.
  • Memory: Linear memory growth relative to result size (removing Map overhead).
  • CPU: Reduced instruction count in the hot path due to the removal of vtable lookups and optimized type checking.

Einswilli and others added 29 commits April 12, 2026 19:33
Benchmarks switched from Vec to smallvec::SmallVec<[SqlValue; 8]> to reduce heap allocations and use SqlWriter for SQL emission. QNode field strings were changed from to_string() to .into(), JSON list values are boxed and built with smallvec::smallvec!, and compile_q calls now accept a mutable SqlWriter. In the compiler, SqlWriter constructors (new_emit, new_no_emit) and fork() were made public so tests/benches can instantiate and reuse writers.
…s and implement high-performance enum dispatch
@Einswilli Einswilli merged commit 800e025 into AllDotPy:master May 9, 2026
3 of 4 checks passed
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