Commit d45a1bb
authored
Cache expensive introspection calls in pyi_generator for faster stub generation (#6187)
* Cache expensive introspection calls in pyi_generator for faster stub generation
Extract repeated inspect.getsource, getfullargspec, inspect.signature,
and module import calls into @cache-decorated helper functions. Replace
inline exec() calls with explicit dict updates for resolving type hints.
Convert all_props from list to set for O(1) membership checks.
Before:
8 files reformatted, 112 files left unchanged
real 4.12
user 5.37
sys 0.33
After:
8 files reformatted, 112 files left unchanged
real 1.93
user 3.00
sys 0.32
* Parallelize pyi stub generation with ProcessPoolExecutor
Pre-import modules sequentially to populate sys.modules, then fork
worker processes for AST parsing, transformation, and file writing.
Extract _write_pyi_file, _get_init_lazy_imports, and _scan_file to
module-level functions. Remove disabled _scan_files_multiprocess.
Reduces generation time from ~1.9s to ~1.45s (~24% faster).
* Return immutable MappingProxyType from cached import/annotation helpers
Cached dicts returned by _get_module_star_imports, _get_module_selected_imports,
_get_class_annotation_globals, and _get_parent_imports are shared across callers.
Wrap them in MappingProxyType to prevent accidental mutation of cached values.
Also remove redundant first ruff format pass.
117 files reformatted, 3 files left unchanged
real 1.57
user 3.93
sys 0.67
* Windows does not support fork 1.55 sec
* cleanup1 parent fe34ae8 commit d45a1bb
1 file changed
Lines changed: 359 additions & 190 deletions
0 commit comments