Make is_awaitable faster for values that are not awaitable
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- backend-api-design, performance
Direzione di ricerca
Inizia individuando is_awaitable nel codice sorgente di graphql-core e leggi i punti in cui viene chiamato e i test esistenti per coroutine, coroutine basate su generatori, futures e oggetti che espongono __await__. Riproduci il benchmark con tests/benchmarks/test_async_iterable.py usando il comando indicato nell’issue, quindi confronta il comportamento e i tempi dopo la modifica proposta all’ordine dei controlli. Il lavoro è completato quando i risultati awaitable e gli errori elencati vengono mantenuti e il caso non-awaitable migliora.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
is_awaitable runs up to three checks for every value.
For a plain value such as an int or a str, it always runs all three.
The executor calls it for every resolved and completed item, so a list of 1,000 items runs it about 2,000 times.
The CoroutineType test does not change the result.
Every coroutine object has an __await__ attribute, so the hasattr check also finds it.
Generator-based coroutines (types.coroutine) have no __await__, so they still need the code-flag check.
A local change removes the CoroutineType test.
It checks the exact generator type first and then checks for __await__.
| Situation | Before | After | Change |
|---|---|---|---|
test_execute_async_iterable_list_field (median) |
1.183 ms | 1.115 ms | 5.8% less time |
| Sync list field with 1,000 items | 1.019 ms | 0.927 ms | 9.0% less time |
| 1,000 async field resolvers (coroutines) | 7.75 ms | 7.83 ms | Within variation: 1.0% more time |
is_awaitable(1) |
102.9 ns | 66.0 ns | 35.9% less time |
is_awaitable(coroutine) |
54.0 ns | 87.8 ns | 62.6% more time |
The coroutine call itself is slower, because hasattr costs more than isinstance.
In a full query this cost stays inside normal variation, because awaiting the coroutine costs much more.
The results are the same for coroutines, generator-based coroutines, futures, and objects with __await__ on the instance, via __getattr__, or via a property.
Errors from a raising __getattr__ or property stay the same.
Environment: CPython 3.12.13, Linux x86-64, one dedicated CPU core.
Base commit: 1d505c19bf5fb8da0205165b78af6094d637009e.
Reproduce on the base and changed versions:
PYTHONPATH=src python -m pytest tests/benchmarks/test_async_iterable.py --benchmark-enable --benchmark-min-rounds=1000
- Lingua principale
- Python
- Stelle
- 534
- Fork
- 159
- Merge medio
- 1g 18h
- PR unite (30g)
- 9
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di graphql-python/graphql-core
-
collect_fields spends extra time on selections without directivesForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
graphql-python/graphql-core#315 ·
I maintainer di solito rispondono entro 1 giorno
-
is_printable_as_block_string checks each character in a Python loopForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
graphql-python/graphql-core#312 ·
I maintainer di solito rispondono entro 1 giorno
-
natural_comparison_key: faster sort keys for names without digitsForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
graphql-python/graphql-core#310 ·
I maintainer di solito rispondono entro 1 giorno
-
assert_name checks each character in a Python generatorForse già presa @swayamdudhela l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
graphql-python/graphql-core#304 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
coerce_input_literal spends extra time on type checks and non-null recursionForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
graphql-python/graphql-core#302 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di graphql-python/graphql-core
Issue simili
-
`destroy` sans terminal répond « Aborted. » au lieu de réclamer `--yes` comme `clean` et `reset`Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
stephrobert/dsoxlab#354 ·
I maintainer di solito rispondono entro 1 giorno
-
hardware help wanted testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
jasonacox/pypowerwall#472 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: DoubleMLRDDData accepts a score_col that is no data column (as in its docstring example); the running variable then becomes a covariate and RDFlex failsForse già presa @vrjdev l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
DoubleML/doubleml-for-py#455 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: Python mod.Box[T] annotation gets a false generic_arg edge that replaces the parameter_type one ('is' on tree-sitter nodes)Forse già presa @rohit-jsfreaky l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
Graphify-Labs/graphify#5110 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni