graphql-core-speedups 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- graphql_core_speedups-0.1.0/Cargo.lock +137 -0
- graphql_core_speedups-0.1.0/Cargo.toml +13 -0
- graphql_core_speedups-0.1.0/LICENSE +21 -0
- graphql_core_speedups-0.1.0/PKG-INFO +124 -0
- graphql_core_speedups-0.1.0/README.md +113 -0
- graphql_core_speedups-0.1.0/crates/core/Cargo.toml +7 -0
- graphql_core_speedups-0.1.0/crates/core/src/lib.rs +27 -0
- graphql_core_speedups-0.1.0/crates/py/Cargo.toml +15 -0
- graphql_core_speedups-0.1.0/crates/py/src/lib.rs +77 -0
- graphql_core_speedups-0.1.0/crates/py/src/spec.rs +149 -0
- graphql_core_speedups-0.1.0/crates/py/src/walk.rs +352 -0
- graphql_core_speedups-0.1.0/pyproject.toml +55 -0
- graphql_core_speedups-0.1.0/python/graphql_core_speedups/__init__.py +5 -0
- graphql_core_speedups-0.1.0/python/graphql_core_speedups/_native.pyi +21 -0
- graphql_core_speedups-0.1.0/python/graphql_core_speedups/executor.py +505 -0
- graphql_core_speedups-0.1.0/python/graphql_core_speedups/py.typed +0 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "graphql-core-speedups-core"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
|
|
9
|
+
[[package]]
|
|
10
|
+
name = "graphql-core-speedups-py"
|
|
11
|
+
version = "0.1.0"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"graphql-core-speedups-core",
|
|
14
|
+
"pyo3",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "heck"
|
|
19
|
+
version = "0.5.0"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
22
|
+
|
|
23
|
+
[[package]]
|
|
24
|
+
name = "libc"
|
|
25
|
+
version = "0.2.191"
|
|
26
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
+
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
|
28
|
+
|
|
29
|
+
[[package]]
|
|
30
|
+
name = "once_cell"
|
|
31
|
+
version = "1.21.4"
|
|
32
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
33
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
34
|
+
|
|
35
|
+
[[package]]
|
|
36
|
+
name = "portable-atomic"
|
|
37
|
+
version = "1.15.0"
|
|
38
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
39
|
+
checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
|
|
40
|
+
|
|
41
|
+
[[package]]
|
|
42
|
+
name = "proc-macro2"
|
|
43
|
+
version = "1.0.107"
|
|
44
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
45
|
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
46
|
+
dependencies = [
|
|
47
|
+
"unicode-ident",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
[[package]]
|
|
51
|
+
name = "pyo3"
|
|
52
|
+
version = "0.30.1"
|
|
53
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
54
|
+
checksum = "229ca13b8a15bb0d1487b81ab975bfcd97513416499a8312011b6036e42e0de4"
|
|
55
|
+
dependencies = [
|
|
56
|
+
"libc",
|
|
57
|
+
"once_cell",
|
|
58
|
+
"portable-atomic",
|
|
59
|
+
"pyo3-build-config",
|
|
60
|
+
"pyo3-ffi",
|
|
61
|
+
"pyo3-macros",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
[[package]]
|
|
65
|
+
name = "pyo3-build-config"
|
|
66
|
+
version = "0.30.1"
|
|
67
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
68
|
+
checksum = "70130e2b6dd1ee589a8788026a429561ca5c40fa7a2fa7914c2282eddae24700"
|
|
69
|
+
dependencies = [
|
|
70
|
+
"target-lexicon",
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
[[package]]
|
|
74
|
+
name = "pyo3-ffi"
|
|
75
|
+
version = "0.30.1"
|
|
76
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
77
|
+
checksum = "5e7ff73c555c286d212d4ce7e5fbda845a973c4f61bd5f160f5f2c3c2a04d1c4"
|
|
78
|
+
dependencies = [
|
|
79
|
+
"libc",
|
|
80
|
+
"pyo3-build-config",
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
[[package]]
|
|
84
|
+
name = "pyo3-macros"
|
|
85
|
+
version = "0.30.1"
|
|
86
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
87
|
+
checksum = "c46d2e5862c7bb8207e3b639f713dda3c499933444784154c11d013c5a691b60"
|
|
88
|
+
dependencies = [
|
|
89
|
+
"proc-macro2",
|
|
90
|
+
"pyo3-macros-backend",
|
|
91
|
+
"quote",
|
|
92
|
+
"syn",
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
[[package]]
|
|
96
|
+
name = "pyo3-macros-backend"
|
|
97
|
+
version = "0.30.1"
|
|
98
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
99
|
+
checksum = "38b89f066f2ae72a2aef52d1537ca2fcd104440ebfadee06e97aa90738a25b9b"
|
|
100
|
+
dependencies = [
|
|
101
|
+
"heck",
|
|
102
|
+
"proc-macro2",
|
|
103
|
+
"quote",
|
|
104
|
+
"syn",
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
[[package]]
|
|
108
|
+
name = "quote"
|
|
109
|
+
version = "1.0.47"
|
|
110
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
111
|
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
112
|
+
dependencies = [
|
|
113
|
+
"proc-macro2",
|
|
114
|
+
]
|
|
115
|
+
|
|
116
|
+
[[package]]
|
|
117
|
+
name = "syn"
|
|
118
|
+
version = "3.0.10"
|
|
119
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
120
|
+
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
|
|
121
|
+
dependencies = [
|
|
122
|
+
"proc-macro2",
|
|
123
|
+
"quote",
|
|
124
|
+
"unicode-ident",
|
|
125
|
+
]
|
|
126
|
+
|
|
127
|
+
[[package]]
|
|
128
|
+
name = "target-lexicon"
|
|
129
|
+
version = "0.13.6"
|
|
130
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
131
|
+
checksum = "8c447be3a2abfa84b2d91680c56600bd6b2873866de27b36ec911be705e291da"
|
|
132
|
+
|
|
133
|
+
[[package]]
|
|
134
|
+
name = "unicode-ident"
|
|
135
|
+
version = "1.0.27"
|
|
136
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
137
|
+
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ernesto Pérez Amigo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: graphql-core-speedups
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Requires-Dist: graphql-core==3.3.2
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Summary: Optional Rust accelerator for graphql-core execution.
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
10
|
+
|
|
11
|
+
# graphql-core-speedups
|
|
12
|
+
|
|
13
|
+
An optional Rust (PyO3) accelerator for [graphql-core](https://github.com/graphql-python/graphql-core)
|
|
14
|
+
execution. Plug it in with one argument; results are graphql-core's own.
|
|
15
|
+
|
|
16
|
+
> **Status: v0.1.** Synchronous execution only, pinned to graphql-core **3.3.2**. Measured results:
|
|
17
|
+
> [docs/v0.1/results.md](docs/v0.1/results.md). Design: [RFC 0001](docs/rfc/0001-graphql-core-accelerator.md).
|
|
18
|
+
>
|
|
19
|
+
> Documentation: <https://eamigo86.github.io/graphql-core-speedups/>
|
|
20
|
+
|
|
21
|
+
## What to expect
|
|
22
|
+
|
|
23
|
+
How much faster depends on how much of the response uses graphql-core's default resolver. Each custom
|
|
24
|
+
resolver hands control back to Python.
|
|
25
|
+
|
|
26
|
+
| Workload | Faster than plain graphql-core |
|
|
27
|
+
|----------|-------------------------------:|
|
|
28
|
+
| Large response from [graphql-core#189](https://github.com/graphql-python/graphql-core/issues/189): 5,000 persons, every field on the default resolver, non-null types, dataclass objects | 13.4–14.5× |
|
|
29
|
+
| Small query on the same schema (one person, 17 fields) | 4.3–4.4× |
|
|
30
|
+
| The large query with a custom resolver on `Person.name` and `Pet.name` | about 1.5× |
|
|
31
|
+
| Operations that cannot use the native path (introspection: every field has a resolver) | no faster, at most 1.5 % slower |
|
|
32
|
+
|
|
33
|
+
- **Ranges, one machine.** The ranges span the v0.1 runs: three of the large and small cases, two of the
|
|
34
|
+
others, each interleaved with plain graphql-core in the same process. All of them ran on one Apple M3 Max
|
|
35
|
+
with CPython 3.12.11. Linux x86-64 and other CPython versions have not been measured yet.
|
|
36
|
+
- **Not 15×.** The spike prototype once measured 15.67× on the large response. The same prototype code
|
|
37
|
+
measures 13.7–13.8× in a later session, so that figure was session variance.
|
|
38
|
+
- **Mixed schemas.** Custom resolvers on just two fields (`Person.name`, `Pet.name`) already bring the large
|
|
39
|
+
case from about 14× down to 1.5×. A schema with resolvers on most fields gains little, but it is not
|
|
40
|
+
slower.
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from graphql import execute_sync, graphql_sync
|
|
46
|
+
from graphql_core_speedups import FastExecutor
|
|
47
|
+
|
|
48
|
+
result = execute_sync(schema, document, root_value, executor_class=FastExecutor)
|
|
49
|
+
result = graphql_sync(schema, source, root_value, executor_class=FastExecutor)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`FastExecutor` is a graphql-core `IncrementalExecutor`. If the compiled extension cannot be imported, it
|
|
53
|
+
warns once and behaves exactly like `IncrementalExecutor`.
|
|
54
|
+
|
|
55
|
+
## What runs natively
|
|
56
|
+
|
|
57
|
+
A field's value is completed in Rust when its whole subtree is plain:
|
|
58
|
+
|
|
59
|
+
- every field uses graphql-core's default resolver (`resolve` is `None` or `default_field_resolver`) and
|
|
60
|
+
takes no arguments;
|
|
61
|
+
- object types have no `is_type_of`; objects under interfaces and unions qualify once graphql-core has
|
|
62
|
+
resolved their runtime type;
|
|
63
|
+
- leaves are any scalar or enum. `String`, `Int`, `Float`, `Boolean`, `ID` and plain enums have native
|
|
64
|
+
fast paths; other values go through graphql-core's own `complete_leaf_value`.
|
|
65
|
+
|
|
66
|
+
The execution must be synchronous with no middleware, the default field resolver and no abort signal,
|
|
67
|
+
and the document must have no directives on fields or fragments (operation-level directives such as
|
|
68
|
+
`@experimental_disableErrorPropagation` are fine). Everything else runs in graphql-core unchanged. When an
|
|
69
|
+
operation cannot use the native path at all, the executor switches to graphql-core's own object and list
|
|
70
|
+
completion. That keeps the cost within the 5 % gate: 0.6–1.5 % slower on introspection across the v0.1
|
|
71
|
+
runs.
|
|
72
|
+
|
|
73
|
+
Errors are completed natively too: on every error path the native walk hands the value it already read
|
|
74
|
+
to graphql-core's own methods, so messages, paths, locations, ordering and null propagation are
|
|
75
|
+
graphql-core's, and no attribute is read twice.
|
|
76
|
+
|
|
77
|
+
## Correctness
|
|
78
|
+
|
|
79
|
+
- **Hypothesis differential test** (`tests/test_differential.py`): this is the main evidence for the
|
|
80
|
+
native path. It draws schemas, data and queries, and requires identical data, errors, key order, and
|
|
81
|
+
logs of attribute reads and resolver calls.
|
|
82
|
+
- **graphql-core 3.3.2's own `tests/execution` suite** runs with `FastExecutor` as the default executor
|
|
83
|
+
(`sh tests/upstream/run.sh`): 738/738, no differences. Most of those tests use custom resolvers, so they
|
|
84
|
+
rarely reach the native path: 26 native completions, in 14 of the 738 tests. The suite mainly shows that
|
|
85
|
+
everything else behaves exactly as graphql-core.
|
|
86
|
+
- **Known difference:** exception `__context__` chaining. Native error boundaries are not inside an
|
|
87
|
+
`except` block. Error objects, messages, paths and locations are identical.
|
|
88
|
+
|
|
89
|
+
## Subclasses and frameworks
|
|
90
|
+
|
|
91
|
+
A framework that needs its own executor class can be combined with `FastExecutor`:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
class Executor(FastExecutor, FrameworkExecutor): ...
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
When an operation cannot use the native path, such a subclass also switches to graphql-core's own object
|
|
98
|
+
and list completion, and keeps its other overrides. A subclass that overrides `complete_object_value` or
|
|
99
|
+
`complete_list_value` itself keeps `FastExecutor`'s hook, because its override must see every call. It
|
|
100
|
+
pays for that on operations that cannot use the native path: 1.26× on introspection for the hook alone,
|
|
101
|
+
before the cost of its own override.
|
|
102
|
+
|
|
103
|
+
- **Ariadne** leaves `resolve=None` on plain fields, so its schemas qualify.
|
|
104
|
+
- **Strawberry** does not reach the native path yet (it passes its own `is_awaitable`). Combined as above,
|
|
105
|
+
it is no slower than Strawberry alone (gate: 1.01×, 1,000 people with 3 friends each).
|
|
106
|
+
- **django-graphex** does not reach the native path yet.
|
|
107
|
+
- **graphene** does not support graphql-core 3.3.
|
|
108
|
+
|
|
109
|
+
Details: [docs/v0.1/results.md](docs/v0.1/results.md#framework-reach).
|
|
110
|
+
|
|
111
|
+
## Development
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
uv sync # builds the extension (release profile)
|
|
115
|
+
uv run pytest -q
|
|
116
|
+
HYPOTHESIS_PROFILE=ci uv run pytest -q tests/test_differential.py
|
|
117
|
+
sh tests/upstream/run.sh
|
|
118
|
+
uv run python -m bench.compare # interleaved plain-vs-fast timings and verdicts
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
[MIT](LICENSE).
|
|
124
|
+
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# graphql-core-speedups
|
|
2
|
+
|
|
3
|
+
An optional Rust (PyO3) accelerator for [graphql-core](https://github.com/graphql-python/graphql-core)
|
|
4
|
+
execution. Plug it in with one argument; results are graphql-core's own.
|
|
5
|
+
|
|
6
|
+
> **Status: v0.1.** Synchronous execution only, pinned to graphql-core **3.3.2**. Measured results:
|
|
7
|
+
> [docs/v0.1/results.md](docs/v0.1/results.md). Design: [RFC 0001](docs/rfc/0001-graphql-core-accelerator.md).
|
|
8
|
+
>
|
|
9
|
+
> Documentation: <https://eamigo86.github.io/graphql-core-speedups/>
|
|
10
|
+
|
|
11
|
+
## What to expect
|
|
12
|
+
|
|
13
|
+
How much faster depends on how much of the response uses graphql-core's default resolver. Each custom
|
|
14
|
+
resolver hands control back to Python.
|
|
15
|
+
|
|
16
|
+
| Workload | Faster than plain graphql-core |
|
|
17
|
+
|----------|-------------------------------:|
|
|
18
|
+
| Large response from [graphql-core#189](https://github.com/graphql-python/graphql-core/issues/189): 5,000 persons, every field on the default resolver, non-null types, dataclass objects | 13.4–14.5× |
|
|
19
|
+
| Small query on the same schema (one person, 17 fields) | 4.3–4.4× |
|
|
20
|
+
| The large query with a custom resolver on `Person.name` and `Pet.name` | about 1.5× |
|
|
21
|
+
| Operations that cannot use the native path (introspection: every field has a resolver) | no faster, at most 1.5 % slower |
|
|
22
|
+
|
|
23
|
+
- **Ranges, one machine.** The ranges span the v0.1 runs: three of the large and small cases, two of the
|
|
24
|
+
others, each interleaved with plain graphql-core in the same process. All of them ran on one Apple M3 Max
|
|
25
|
+
with CPython 3.12.11. Linux x86-64 and other CPython versions have not been measured yet.
|
|
26
|
+
- **Not 15×.** The spike prototype once measured 15.67× on the large response. The same prototype code
|
|
27
|
+
measures 13.7–13.8× in a later session, so that figure was session variance.
|
|
28
|
+
- **Mixed schemas.** Custom resolvers on just two fields (`Person.name`, `Pet.name`) already bring the large
|
|
29
|
+
case from about 14× down to 1.5×. A schema with resolvers on most fields gains little, but it is not
|
|
30
|
+
slower.
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from graphql import execute_sync, graphql_sync
|
|
36
|
+
from graphql_core_speedups import FastExecutor
|
|
37
|
+
|
|
38
|
+
result = execute_sync(schema, document, root_value, executor_class=FastExecutor)
|
|
39
|
+
result = graphql_sync(schema, source, root_value, executor_class=FastExecutor)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`FastExecutor` is a graphql-core `IncrementalExecutor`. If the compiled extension cannot be imported, it
|
|
43
|
+
warns once and behaves exactly like `IncrementalExecutor`.
|
|
44
|
+
|
|
45
|
+
## What runs natively
|
|
46
|
+
|
|
47
|
+
A field's value is completed in Rust when its whole subtree is plain:
|
|
48
|
+
|
|
49
|
+
- every field uses graphql-core's default resolver (`resolve` is `None` or `default_field_resolver`) and
|
|
50
|
+
takes no arguments;
|
|
51
|
+
- object types have no `is_type_of`; objects under interfaces and unions qualify once graphql-core has
|
|
52
|
+
resolved their runtime type;
|
|
53
|
+
- leaves are any scalar or enum. `String`, `Int`, `Float`, `Boolean`, `ID` and plain enums have native
|
|
54
|
+
fast paths; other values go through graphql-core's own `complete_leaf_value`.
|
|
55
|
+
|
|
56
|
+
The execution must be synchronous with no middleware, the default field resolver and no abort signal,
|
|
57
|
+
and the document must have no directives on fields or fragments (operation-level directives such as
|
|
58
|
+
`@experimental_disableErrorPropagation` are fine). Everything else runs in graphql-core unchanged. When an
|
|
59
|
+
operation cannot use the native path at all, the executor switches to graphql-core's own object and list
|
|
60
|
+
completion. That keeps the cost within the 5 % gate: 0.6–1.5 % slower on introspection across the v0.1
|
|
61
|
+
runs.
|
|
62
|
+
|
|
63
|
+
Errors are completed natively too: on every error path the native walk hands the value it already read
|
|
64
|
+
to graphql-core's own methods, so messages, paths, locations, ordering and null propagation are
|
|
65
|
+
graphql-core's, and no attribute is read twice.
|
|
66
|
+
|
|
67
|
+
## Correctness
|
|
68
|
+
|
|
69
|
+
- **Hypothesis differential test** (`tests/test_differential.py`): this is the main evidence for the
|
|
70
|
+
native path. It draws schemas, data and queries, and requires identical data, errors, key order, and
|
|
71
|
+
logs of attribute reads and resolver calls.
|
|
72
|
+
- **graphql-core 3.3.2's own `tests/execution` suite** runs with `FastExecutor` as the default executor
|
|
73
|
+
(`sh tests/upstream/run.sh`): 738/738, no differences. Most of those tests use custom resolvers, so they
|
|
74
|
+
rarely reach the native path: 26 native completions, in 14 of the 738 tests. The suite mainly shows that
|
|
75
|
+
everything else behaves exactly as graphql-core.
|
|
76
|
+
- **Known difference:** exception `__context__` chaining. Native error boundaries are not inside an
|
|
77
|
+
`except` block. Error objects, messages, paths and locations are identical.
|
|
78
|
+
|
|
79
|
+
## Subclasses and frameworks
|
|
80
|
+
|
|
81
|
+
A framework that needs its own executor class can be combined with `FastExecutor`:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
class Executor(FastExecutor, FrameworkExecutor): ...
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
When an operation cannot use the native path, such a subclass also switches to graphql-core's own object
|
|
88
|
+
and list completion, and keeps its other overrides. A subclass that overrides `complete_object_value` or
|
|
89
|
+
`complete_list_value` itself keeps `FastExecutor`'s hook, because its override must see every call. It
|
|
90
|
+
pays for that on operations that cannot use the native path: 1.26× on introspection for the hook alone,
|
|
91
|
+
before the cost of its own override.
|
|
92
|
+
|
|
93
|
+
- **Ariadne** leaves `resolve=None` on plain fields, so its schemas qualify.
|
|
94
|
+
- **Strawberry** does not reach the native path yet (it passes its own `is_awaitable`). Combined as above,
|
|
95
|
+
it is no slower than Strawberry alone (gate: 1.01×, 1,000 people with 3 friends each).
|
|
96
|
+
- **django-graphex** does not reach the native path yet.
|
|
97
|
+
- **graphene** does not support graphql-core 3.3.
|
|
98
|
+
|
|
99
|
+
Details: [docs/v0.1/results.md](docs/v0.1/results.md#framework-reach).
|
|
100
|
+
|
|
101
|
+
## Development
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
uv sync # builds the extension (release profile)
|
|
105
|
+
uv run pytest -q
|
|
106
|
+
HYPOTHESIS_PROFILE=ci uv run pytest -q tests/test_differential.py
|
|
107
|
+
sh tests/upstream/run.sh
|
|
108
|
+
uv run python -m bench.compare # interleaved plain-vs-fast timings and verdicts
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
[MIT](LICENSE).
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//! Pure-Rust core of graphql-core-speedups: logic that needs no Python.
|
|
2
|
+
|
|
3
|
+
/// Smallest value of the GraphQL `Int` scalar, `-(2^31)`.
|
|
4
|
+
pub const GRAPHQL_INT_MIN: i64 = -(1 << 31);
|
|
5
|
+
|
|
6
|
+
/// Largest value of the GraphQL `Int` scalar, `2^31 - 1`.
|
|
7
|
+
pub const GRAPHQL_INT_MAX: i64 = (1 << 31) - 1;
|
|
8
|
+
|
|
9
|
+
/// Tell whether `n` is representable as a GraphQL `Int` (a signed 32-bit integer).
|
|
10
|
+
#[must_use]
|
|
11
|
+
pub fn is_graphql_int(n: i64) -> bool {
|
|
12
|
+
(GRAPHQL_INT_MIN..=GRAPHQL_INT_MAX).contains(&n)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
#[cfg(test)]
|
|
16
|
+
mod tests {
|
|
17
|
+
use super::*;
|
|
18
|
+
|
|
19
|
+
#[test]
|
|
20
|
+
fn int_range_is_signed_32_bit() {
|
|
21
|
+
assert!(is_graphql_int(0));
|
|
22
|
+
assert!(is_graphql_int(i64::from(i32::MIN)));
|
|
23
|
+
assert!(is_graphql_int(i64::from(i32::MAX)));
|
|
24
|
+
assert!(!is_graphql_int(i64::from(i32::MIN) - 1));
|
|
25
|
+
assert!(!is_graphql_int(i64::from(i32::MAX) + 1));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "graphql-core-speedups-py"
|
|
3
|
+
description = "PyO3 bindings for graphql-core-speedups."
|
|
4
|
+
version.workspace = true
|
|
5
|
+
edition.workspace = true
|
|
6
|
+
license.workspace = true
|
|
7
|
+
publish.workspace = true
|
|
8
|
+
|
|
9
|
+
[lib]
|
|
10
|
+
name = "_native"
|
|
11
|
+
crate-type = ["cdylib"]
|
|
12
|
+
|
|
13
|
+
[dependencies]
|
|
14
|
+
pyo3 = { version = "0.30.1", features = ["abi3-py312", "extension-module"] }
|
|
15
|
+
graphql-core-speedups-core = { path = "../core" }
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//! PyO3 bindings for graphql-core-speedups.
|
|
2
|
+
|
|
3
|
+
mod spec;
|
|
4
|
+
mod walk;
|
|
5
|
+
|
|
6
|
+
use pyo3::prelude::*;
|
|
7
|
+
use pyo3::types::{PyList, PyTuple};
|
|
8
|
+
|
|
9
|
+
use crate::spec::{Kind, Node};
|
|
10
|
+
use crate::walk::Walk;
|
|
11
|
+
|
|
12
|
+
/// A compiled completion plan for one field: its return type and its selection set.
|
|
13
|
+
///
|
|
14
|
+
/// `complete` walks a resolved value the way graphql-core's `complete_value` would. The hot
|
|
15
|
+
/// path stays native; every cold path (errors, nulls in non-null slots, non-list iterables,
|
|
16
|
+
/// scalars off their fast path) is handed to the executor's own graphql-core methods with the
|
|
17
|
+
/// value already read, so results, errors, paths and null propagation are graphql-core's.
|
|
18
|
+
#[pyclass(frozen, module = "graphql_core_speedups._native")]
|
|
19
|
+
pub struct Plan {
|
|
20
|
+
root: Node,
|
|
21
|
+
undefined: Py<PyAny>,
|
|
22
|
+
mapping: Py<PyAny>,
|
|
23
|
+
abort: Py<PyAny>,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#[pymethods]
|
|
27
|
+
impl Plan {
|
|
28
|
+
/// Build a plan from the nested-tuple `spec` and the Python objects the walk compares with.
|
|
29
|
+
///
|
|
30
|
+
/// `undefined` is graphql-core's `Undefined`, `mapping` is `collections.abc.Mapping` and
|
|
31
|
+
/// `abort` is the sentinel `complete` returns for a root list that is not a list or tuple.
|
|
32
|
+
#[new]
|
|
33
|
+
fn new(
|
|
34
|
+
spec: &Bound<'_, PyTuple>,
|
|
35
|
+
undefined: Py<PyAny>,
|
|
36
|
+
mapping: Py<PyAny>,
|
|
37
|
+
abort: Py<PyAny>,
|
|
38
|
+
) -> PyResult<Self> {
|
|
39
|
+
Ok(Self {
|
|
40
|
+
root: Node::parse(spec.as_any())?,
|
|
41
|
+
undefined,
|
|
42
|
+
mapping,
|
|
43
|
+
abort,
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// Complete `value`, the resolved value of the field whose resolve info, response path and
|
|
48
|
+
/// field-details list are `info`, `path` and `fdl`, with `executor`'s graphql-core methods.
|
|
49
|
+
///
|
|
50
|
+
/// Returns the response value, raises what graphql-core would propagate, or returns the
|
|
51
|
+
/// abort sentinel when the root is a list and `value` is not an exact list or tuple.
|
|
52
|
+
fn complete<'py>(
|
|
53
|
+
&self,
|
|
54
|
+
py: Python<'py>,
|
|
55
|
+
value: &Bound<'py, PyAny>,
|
|
56
|
+
executor: &Bound<'py, PyAny>,
|
|
57
|
+
info: &Bound<'py, PyAny>,
|
|
58
|
+
path: &Bound<'py, PyAny>,
|
|
59
|
+
fdl: &Bound<'py, PyAny>,
|
|
60
|
+
) -> PyResult<Py<PyAny>> {
|
|
61
|
+
if matches!(self.root.kind, Kind::List(_))
|
|
62
|
+
&& !(value.is_exact_instance_of::<PyList>() || value.is_exact_instance_of::<PyTuple>())
|
|
63
|
+
{
|
|
64
|
+
return Ok(self.abort.clone_ref(py));
|
|
65
|
+
}
|
|
66
|
+
let mut walk = Walk::new(py, &self.undefined, &self.mapping, executor, info, path, fdl);
|
|
67
|
+
Ok(walk.complete(&self.root, value)?.unbind())
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/// Native extension module, imported as `graphql_core_speedups._native`.
|
|
72
|
+
#[pymodule]
|
|
73
|
+
fn _native(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|
74
|
+
m.add("__version__", env!("CARGO_PKG_VERSION"))?;
|
|
75
|
+
m.add_class::<Plan>()?;
|
|
76
|
+
Ok(())
|
|
77
|
+
}
|