Speed up LexicalDistance.measure used for "Did you mean" suggestions
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 75/100
- Tipo di issue
- Refactoring
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- backend-api-design, performance
Direzione di ricerca
Start by locating LexicalDistance.measure() and its callers in suggestion_list(); the issue names tests/benchmarks/test_validate_invalid_gql.py as a performance benchmark. Read the current distance calculation and run that benchmark to establish a baseline. Implement the proposed prefix/suffix trimming, threshold early return, and row-buffer changes, then compare benchmark results and check that suggestion behavior remains correct.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem
suggestion_list() calls LexicalDistance.measure() once for each option. When a query has a typo, validation uses this to build "Did you mean ...?" hints. On large schemas, this distance code takes most of the validation time.
The method does extra work for each option:
- It builds the full distance table even when a shared prefix or suffix needs no edits.
- It builds the table even when the option has more missing characters than the threshold allows.
- It calls
min()with three values in every cell, even when the two characters are equal. - It converts the option to a list of code points on every call.
Numbers
Python 3.12 on Linux. The Before column is the current main, and the After column is the proposed change.
| Situation | Before | After | Change |
|---|---|---|---|
tests/benchmarks/test_validate_invalid_gql.py (median) |
22.49 ms | 11.42 ms | 49% faster |
suggestion_list, 12-char typo, 2000 random names |
27.04 ms | 2.69 ms | 90% faster |
suggestion_list, 4-char typo, 2000 random names |
2.28 ms | 0.61 ms | 73% faster |
suggestion_list, 30-char input, 2000 random names |
0.70 ms | 0.30 ms | 58% faster |
| Exact or case-only matches, 2000 options | 0.170 ms | 0.179 ms | about the same (early return, code unchanged) |
Proposed fix
Skip the common prefix and suffix, and return early when too many characters are missing. In the table, copy the diagonal cell for equal characters, and rotate the row buffers.
Environment
graphql-core main (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
-
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
-
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
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