Zero-copy JSON passthrough from PostgreSQL to client. No Python object instantiation overhead.
TurboRouter enables direct JSON passthrough from PostgreSQL to the client. Instead of deserializing JSONB into Python objects and re-serializing back to JSON, TurboRouter streams the database response directly to the client—eliminating the entire Python object instantiation layer.
| Stage | Standard GraphQL | TurboRouter |
|---|---|---|
| Query Parsing | 0.5ms | âś… 0ms |
| Schema Validation | 0.3ms | âś… 0ms |
| Query Planning | 0.2ms | âś… 0ms |
| Hash Lookup (APQ) | - | 0.05ms |
| PostgreSQL JSONB Query | 5ms | 5ms |
| Deserialize JSONB → Python Objects | 2-8ms | ✅ 0ms (skipped) |
| Serialize Python Objects → JSON | 2-6ms | ✅ 0ms (skipped) |
| JSON Passthrough | - | âś… ~0.05ms |
| Total | 10-20ms | âś… ~5.1ms |
from fraiseql.fastapi import TurboQuery, TurboRegistry
registry = TurboRegistry()
user_query = TurboQuery(
graphql_query="""
query GetUser($id: ID!) {
user(id: $id) {
id
name
email
posts {
title
publishedAt
}
}
}
""",
sql_template="""
SELECT jsonb_build_object(
'user', jsonb_build_object(
'id', u.id,
'name', u.data->>'name',
'email', u.data->>'email',
'posts', COALESCE(
jsonb_agg(...)
)
)
) as result
FROM users u
LEFT JOIN posts p ON p.user_id = u.id
WHERE u.id = %(id)s::int
GROUP BY u.id
""",
param_mapping={"id": "id"}
)
registry.register(user_query)
# PostgreSQL returns JSONB:
{
"user": {
"id": 123,
"name": "Alice",
"email": "alice@example.com",
"posts": [...]
}
}
# TurboRouter: Stream it directly!
# ❌ No Python object creation
# ❌ No serialization overhead
# âś… Zero-copy passthrough
# Application overhead: ~0.1ms ⚡
Eliminate Python object instantiation and JSON serialization overhead
PostgreSQL JSONB flows directly to client without intermediate transformations
No temporary Python objects allocated—reduces GC pressure significantly
Handle 2-5x more requests per second with the same hardware
# Enable in production
app = create_fraiseql_app(
database_url="postgresql://...",
types=[User, Post],
production=True, # Enables TurboRouter
)
# Configure via environment
FRAISEQL_ENABLE_TURBO_ROUTER=true
FRAISEQL_TURBO_ROUTER_CACHE_SIZE=2000
# Or via config object
config = FraiseQLConfig(
enable_turbo_router=True,
turbo_router_cache_size=5000
)
TurboRouter is available now in FraiseQL 0.1.0+