natural_comparison_key: faster sort keys for names without digits
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- performance
Direzione di ricerca
Inizia da natural_comparison_key in src/graphql/pyutils/natural_compare.py e leggi tests/pyutils/test_natural_compare.py. Verifica che il percorso rapido proposto e l’assegnazione di slice preservino le chiavi esistenti, quindi esegui il file di test indicato. Il lavoro è completato quando i test passano e l’ottimizzazione mantiene invariate le chiavi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
natural_comparison_key in src/graphql/pyutils/natural_compare.py runs for every name when lexicographic_sort_schema sorts a schema. It is also used by suggestion_list and sort_value_node.
Problem
The function always splits the name with a regex. Then it walks the parts with zip and itertools.cycle inside a generator. Most GraphQL names (userName, createdAt) have no digits. For these names, this work always gives the same one-item tuple (name,).
Numbers
I measured the current code and a small change with timeit (CPython 3.12, Linux). The table shows the time to compute the keys for each list of names.
| Situation | Current | Proposed | Change |
|---|---|---|---|
| GitHub schema names (3323 names) | 2.11 ms | 0.34 ms | 84% faster |
Letters only, userName (5000 names) |
3.00 ms | 0.38 ms | 88% faster |
Underscore names, USER_NAME (5000 names) |
3.09 ms | 1.83 ms | 41% faster |
Names with numbers, field12x3 (5000 names) |
5.61 ms | 3.72 ms | 34% faster |
Proposed fix
Return (key,) early when key.isalpha() is true, because such a name cannot contain a decimal digit. For other names, keep the regex split and replace the digit parts in one slice assignment instead of the zip/cycle generator. The keys stay exactly the same, and the existing tests in tests/pyutils/test_natural_compare.py pass.
Environment
- graphql-core
mainat 1d505c1 - CPython 3.12, Linux x86_64
- 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
-
Make is_awaitable faster for values that are not awaitableForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
graphql-python/graphql-core#308 ·
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
-
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
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
assafelovic/gpt-researcher#2277 ·
I maintainer di solito rispondono entro 10 giorni