Speed up LexicalDistance.measure used for "Did you mean" suggestions
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 75/100
- Issue-Typ
- Refactoring
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- python
- Bereich
- backend-api-design, performance
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Python
- Sterne
- 534
- Forks
- 159
- Ø Merge
- 1 T. 18 Std.
- Gemergte PRs (30 T.)
- 9
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Kein Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus graphql-python/graphql-core
-
collect_fields spends extra time on selections without directivesEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
graphql-python/graphql-core#315 ·
Maintainer antworten meist innerhalb von 1 Tag
-
is_printable_as_block_string checks each character in a Python loopEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
graphql-python/graphql-core#312 ·
Maintainer antworten meist innerhalb von 1 Tag
-
natural_comparison_key: faster sort keys for names without digitsEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
graphql-python/graphql-core#310 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Make is_awaitable faster for values that are not awaitableEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
graphql-python/graphql-core#308 ·
Maintainer antworten meist innerhalb von 1 Tag
-
assert_name checks each character in a Python generatorEvtl. vergeben @swayamdudhela hat das vor 2 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
graphql-python/graphql-core#304 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in graphql-python/graphql-core
Ähnliche Issues
-
Document style: tablesOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
-
Successor registrant to review: Navient Holdings, Inc. (CIK 2152623), 8-K12B 0001193125-26-436899Offensuccessor-review
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
dgunning/edgartools#1889 ·
Maintainer antworten meist innerhalb von 1 Tag
-
`destroy` sans terminal répond « Aborted. » au lieu de réclamer `--yes` comme `clean` et `reset`Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
stephrobert/dsoxlab#354 ·
Maintainer antworten meist innerhalb von 1 Tag
-
hardware help wanted testing
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
mediajunkie/piper-morgan-product#2335 · 1 Kommentar ·