Option to skip per-method docstring generation in build() (memory / high-concurrency)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 52/100
Hướng nghiên cứu
Bắt đầu từ build() và lần theo discovery.createMethod, schema.Schemas.prettyPrintSchema và prettyPrintByName để xem các docstring của response-schema được tạo ở đâu trong quá trình khởi tạo service và sub-resource lazy. Tái hiện memory profile của Sheets v4 được mô tả trong issue; công việc được xem là hoàn tất khi một tùy chọn build-time được hỗ trợ bỏ qua việc tạo này mà không ảnh hưởng đến quá trình khởi tạo thông thường khi được bật.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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).
- Ngôn ngữ chính
- Python
- Star
- 8.9k
- Fork
- 2.6k
- Merge trung bình
- 2 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 15
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của googleapis/google-api-python-client
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
test: connection leak test test_discovery_http_is_closed is shadowed and syntactically invalid Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
samples type: docs
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
-
YouTube Data API videos.insert returns hidden “Video Uploads per day” 429 despite quota headroom Đang mởpriority: p2 type: bug
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
googleapis/google-api-python-client#2753 · 5 reaction ·
Tất cả issue của googleapis/google-api-python-client
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
anthropics/skills#1811 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
speaches-ai/speaches#678 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
datalayer/mcp-compose#42 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
conda-forge/spacy-feedstock#177 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
UKGovernmentBEIS/inspect_evals#2523 ·