Repository navigation
High memory usage with a PEP 420 namespace package split across distributions #11540
|
Hi Pyright maintainers, GitHubKit 0.16.0 moved its generated schema modules into several independently installable distributions. These distributions contribute subpackages to the same PEP 420 namespace package: There is intentionally no top-level After this change, Pyright import resolution became significantly slower and more memory-intensive. In GitHubKit CI, we currently need: NODE_OPTIONS: --max-old-space-size=12288to reduce the chance of Pyright being terminated. A downstream project also reported the following controlled comparison:
The number of checked files remained almost unchanged. The most interesting result is that adding an empty file: restores the previous performance:
This suggests that import resolution for the implicit namespace package is the main trigger. Users can work around the issue by adding an empty Is this expected behavior for a namespace package spread across multiple distributions? Is there a recommended configuration or packaging approach that preserves the namespace package without this performance cost? Related |
Replies: 2 comments 2 replies
|
I checked a smaller public input while keeping the split namespace intact: GitHubKit v0.16.0 at 7dfc9f3, checking only Using pinned npm Pyright packages on Debian x86-64, Node 24.19.0 and Python 3.12.14 (uv 0.12.23),
Every run checked one file and finished with zero diagnostics. Parsed/bound counts were 3,129 versus 3,127; I haven't identified the two-file difference. Runs alternated old then new, the OS page cache was not flushed, and both used To recreate the input, use that GitHubKit commit's unchanged node --max-old-space-size=1536 /path/to/pyright/index.js \
--pythonpath /path/to/venv/bin/python --stats \
tests/test_unit_test/test_event_hooks.pyThe original 532-file project and dependency set were unavailable, so this only supplies a smaller version-comparison input, not a reproduction of the original report. |
|
Hi Ju4tCode (@yanyongyu), hope you're doing well! Thanks for the really careful write up, and thanks 배경한 | Kyunghan Bae (@qorud02) for the version comparison, it pointed me at the right place. Short answer: it isn't a general cost of namespace packages. It comes from one pattern in the generated Why
An empty Measurements (pyright 1.1.414 and 1.1.402 from npm, Node 26, Python 3.12, macOS, githubkit 0.16.1 with
On the githubkit dev checkout (editable workspace, Workaround that keeps the namespace The template already emits one line per name (models.py.jinja#L9-L12), and the codegen script runs [tool.ruff.lint.isort]
force-sort-within-sections = true
extra-standard-library = ["typing_extensions"]
combine-as-imports = trueAfter On the pyright side, I also tried only bypassing the cache when the last resolved part really is a namespace directory (an empty last entry in
Does merging the imports bring your CI back under the default heap too? It would be great to hear from anyone else with a split namespace package whether they see the same pattern. |

Hi Ju4tCode (@yanyongyu), hope you're doing well! Thanks for the really careful write up, and thanks 배경한 | Kyunghan Bae (@qorud02) for the version comparison, it pointed me at the right place.
Short answer: it isn't a general cost of namespace packages. It comes from one pattern in the generated
githubkit_schemas/latest/models.pyandlatest/types.py: each imports 4552 names as 4552 separatefrom githubkit_schemas.v2026_03_10.models import X as Xstatements, and because the top levelgithubkit_schemasis a namespace, pyright ignores its import cache for every one of them. Collapsing those into onefrom ... import (...)statement per module brings the old numbers back while keeping the name…