Option to skip per-method docstring generation in build() (memory / high-concurrency)
还没有人认领这个 Issue。
评估
调研方向
从 build() 开始,跟踪 discovery.createMethod、schema.Schemas.prettyPrintSchema 和 prettyPrintByName,查看在构造 service 和 lazy sub-resource 期间 response-schema docstring 是在哪里生成的。复现 issue 中描述的 Sheets v4 内存配置;当一个受支持的 build-time 选项可以跳过该生成过程,并且启用后不影响正常构造时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
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).
- 主要语言
- Python
- 星标
- 8.9k
- 派生
- 2.6k
- 平均合并
- 2 天 1 小时
- 30 天内合并 PR
- 16
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
googleapis/google-api-python-client 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 1/5 1 小时以内 新手友好度 92/100
-
เมตาแมส 未关闭
难度 1/5 1 小时以内 新手友好度 10/100
-
samples type: docs
难度 3/5 1-2 天 新手友好度 52/100
查看 googleapis/google-api-python-client 的全部 Issue
相似的 Issue
-
area: harness bug status: needs-triage
难度 2/5 1-3 小时 新手友好度 75/100
Human-Agent-Society/reef#625 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 1/5 1 小时以内 新手友好度 80/100
learningequality/kolibri#15351 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
Name consistency 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
eellak/triplestore#65 · 1 条评论 ·