Option to skip per-method docstring generation in build() (memory / high-concurrency)
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 52/100
Rechercherichtung
Beginne bei build() und verfolge discovery.createMethod, schema.Schemas.prettyPrintSchema und prettyPrintByName, um zu sehen, wo response-schema-Dokumentstrings während der Erstellung von Services und verzögerten Subressourcen erzeugt werden. Reproduziere das im Issue beschriebene Speicherprofil von Sheets v4; die Aufgabe ist abgeschlossen, wenn eine unterstützte Build-Zeit-Option diese Erzeugung überspringt, ohne die normale Erstellung zu beeinflussen, wenn sie aktiviert ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Feature request: an option to skip per-method docstring generation in build()
Problem
build() (and lazy sub-resource construction) generates a fully-expanded, recursively
pretty-printed prototype of each method's response schema and attaches it as
method.__doc__ (discovery.createMethod → schema.Schemas.prettyPrintSchema /
prettyPrintByName). For APIs with large, deeply-nested schemas this is very expensive, and it
is paid every time a service/resource is constructed.
Concrete numbers from profiling Sheets v4 (google-api-python-client==2.198.0, Python 3.13),
measured with RSS (no tracemalloc, to avoid its overhead):
- Building the service, then touching one sub-resource (
service.spreadsheets(), no API
call): ~66 MB. - Of that, ~99.9% is the docstring schema expansion — no-oping
prettyPrintSchema/
prettyPrintByNamedrops it to ~1 MB. The.spreadsheets()methods themselves are ~24 KB. - The docstrings are only useful for interactive
help(); in a server they are never read.
Impact
In a concurrent server (a fresh service built per request, common with per-user credentials),
these allocations are not shared across in-flight requests. 8 concurrent Sheets requests
each build ~66 MB of docstrings simultaneously ≈ 530 MB peak, which OOM-kills a
memory-limited container. This is the concurrent-peak sibling of the long-standing
reference-cycle memory issue in #535 (whose recommended fix — build/reuse a single service — is
not always feasible when credentials differ per request).
Request
A supported way to skip docstring generation at build time, e.g.:
build("sheets", "v4", credentials=creds, generate_docstrings=False)
# or a module/env toggle
Today the only options are to monkeypatch Schemas.prettyPrintSchema/prettyPrintByName
(fragile across versions) or fork. A first-class flag would let memory-constrained / high-
concurrency deployments opt out of documentation strings they never use.
Environment
google-api-python-client==2.198.0, Python 3.13- Reproly: build any large-schema API (Sheets v4), touch a sub-resource, measure RSS; repeat
concurrently to see the multiplier.
Related: #535 (memory from repeated build() / reference cycles).
- Vorherrschende Sprache
- Python
- Sterne
- 8.9k
- Forks
- 2.6k
- Ø Merge
- 2 T. 17 Std.
- Gemergte PRs (30 T.)
- 10
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
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 googleapis/google-api-python-client
-
Disable prettyPrint by default for Google Sheets API responsesEvtl. vergeben @pawciobiel hat das vor 59 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
googleapis/google-api-python-client#2788 ·
Maintainer antworten meist innerhalb von 1 Tag
-
test: connection leak test test_discovery_http_is_closed is shadowed and syntactically invalidEvtl. vergeben @Capstan hat das vor 134 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
googleapis/google-api-python-client#2757 ·
Maintainer antworten meist innerhalb von 1 Tag
-
test: strict positional parameter enforcement is ignored under pytestEvtl. vergeben @Capstan hat das vor 134 Tagen übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 92/100
googleapis/google-api-python-client#2755 ·
Maintainer antworten meist innerhalb von 1 Tag
-
forms for APOffen
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 20/100
googleapis/google-api-python-client#2830 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
googleapis/google-api-python-client#2825 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in googleapis/google-api-python-client
Ähnliche Issues
-
bug Triage-Needed
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
FuRongJun-1999/dsh-memory#170 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 82/100
521xueweihan/HelloGitHub#3940 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100