Performance helpers for strawberry-django: skip resolver overhead on sync Django.
Project description
fastberry
Performance helpers for strawberry-django GraphQL schemas running under synchronous Django.
strawberry-django wraps every field resolver in django_resolver, which calls
in_async_context() on each resolution. Under sync Django that call raises and
catches a RuntimeError internally (~0.15 ms per field). On large result sets
this dominates response time — pure CPU overhead with zero extra database
queries.
fastberry lets you opt specific "hot" types out of that machinery.
Install
pip install fastberry
Requires Python 3.10+, Django 4.2+, and strawberry-graphql.
Usage
Mark hot types with @fast_path (outermost, after @strawberry_django.type)
and register FastPathExtension on the schema:
import strawberry
import strawberry_django
from fastberry import fast_path, FastPathExtension
from myapp.models import Stock
@fast_path
@strawberry_django.type(Stock, disable_optimization=True)
class StockType:
id: int
title: str
@strawberry.type
class Query:
stocks: list[StockType] = strawberry_django.field()
schema = strawberry.Schema(
query=Query,
extensions=[FastPathExtension],
)
Only types decorated with @fast_path take the fast path; everything else
resolves normally. To turn the optimization off, remove the extension (global)
or the decorator (per type).
How it works
- Plain fields resolve via a direct
getattr(root, attr). Related managers (*-to-many) are materialized with.all(). - Custom resolvers are called directly, bypassing the
django_resolverwrapper.
The field→resolver map is built once, at class-definition time, and keyed by the
GraphQL type name (info.parent_type.name) — not the Python class — because at
resolve time root is the Django model instance, not the Strawberry type.
Benchmarks
Indicative numbers from a real schema (~3000 objects, ~27 fields each):
| Scenario | Without fast-path | With fast-path | Speedup |
|---|---|---|---|
stocks_by_house |
4.4 s | 1.8 s | ~2.4× |
Your mileage will vary with field count and result-set size.
Caveats
- Built for sync Django execution. Async schemas don't hit the overhead this targets.
@fast_pathdoes its own field resolution, so it skips any custom logic thatdjango_resolverwould otherwise apply. Use it on read-heavy, plain types; keep complex types on the default path.
Links
- Source: https://github.com/davidsarosi92/fastberry
- Issues: https://github.com/davidsarosi92/fastberry/issues
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastberry-0.1.0.tar.gz.
File metadata
- Download URL: fastberry-0.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
577ecad08b82fc022775f0449cacbcb7e43a3dc7cd30a9044e2ff1f59103cc6d
|
|
| MD5 |
dc591fc1d92a8312bef7c05448022deb
|
|
| BLAKE2b-256 |
5ac6320ac1e64ccb9ecb99d71b10dbd683d55e764a5a134ff2bc88871bda48c6
|
Provenance
The following attestation bundles were made for fastberry-0.1.0.tar.gz:
Publisher:
release.yml on davidsarosi92/fastberry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastberry-0.1.0.tar.gz -
Subject digest:
577ecad08b82fc022775f0449cacbcb7e43a3dc7cd30a9044e2ff1f59103cc6d - Sigstore transparency entry: 1674914909
- Sigstore integration time:
-
Permalink:
davidsarosi92/fastberry@0db6dfbd52ad0a3b7b69b31dd03f2ab6f09e8c85 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/davidsarosi92
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0db6dfbd52ad0a3b7b69b31dd03f2ab6f09e8c85 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastberry-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastberry-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
177a7cf184ae9c43558244f4fd5a2ac37125dda454266fa6fa2fe6b8c9c35a6e
|
|
| MD5 |
ee66bc56d24de4885013f67e06dbbd95
|
|
| BLAKE2b-256 |
991b3438ea2a880c7b4c2bf8d19bd0b8ab51bbbf041e5a3a819a07a29708b2d8
|
Provenance
The following attestation bundles were made for fastberry-0.1.0-py3-none-any.whl:
Publisher:
release.yml on davidsarosi92/fastberry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastberry-0.1.0-py3-none-any.whl -
Subject digest:
177a7cf184ae9c43558244f4fd5a2ac37125dda454266fa6fa2fe6b8c9c35a6e - Sigstore transparency entry: 1674914932
- Sigstore integration time:
-
Permalink:
davidsarosi92/fastberry@0db6dfbd52ad0a3b7b69b31dd03f2ab6f09e8c85 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/davidsarosi92
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0db6dfbd52ad0a3b7b69b31dd03f2ab6f09e8c85 -
Trigger Event:
push
-
Statement type: