FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Memoize the options snapshot by KevinRK29 · Pull Request #21354 · python/mypy · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
22 changes: 16 additions & 6 deletions mypy/build.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,10 @@ def __init__(
self.import_options: dict[str, bytes] = {}
# Cache for transitive dependency check (expensive).
self.transitive_deps_cache: dict[tuple[int, int], bool] = {}
# Cache for options_snapshot() keyed by the cloned Options. Options is
# hashed by identity, and most modules share a handful of distinct
# configs, so this collapses ~all calls onto a few entries.
self.options_snapshot_cache: dict[Options, tuple[str, str]] = {}
# Packages for which we know presence or absence of __getattr__().
self.known_partial_packages: dict[str, bool] = {}

Expand Down Expand Up @@ -1966,23 +1970,29 @@ def get_cache_names(id: str, path: str, options: Options) -> tuple[str, str, str
return prefix + meta_suffix, prefix + data_suffix, deps_json


def options_snapshot(id: str, manager: BuildManager) -> dict[str, object]:
def options_snapshot(module: str, manager: BuildManager) -> dict[str, object]:
"""Make compact snapshot of options for a module.

Separately store only the options we may compare individually, and take a hash
of everything else. If --debug-cache is specified, fall back to full snapshot.
"""
platform_opt, values = manager.options.clone_for_module(id).select_options_affecting_cache()
cloned = manager.options.clone_for_module(module)
if manager.options.debug_cache:
# Build full options snapshot for debugging purposes.
platform_opt, values = cloned.select_options_affecting_cache()
result: dict[str, object] = {"platform": platform_opt}
for key, val in zip(OPTIONS_AFFECTING_CACHE_NO_PLATFORM, values):
result[key] = val
return result
# Process most options quickly, since this is performance critical.
buf = WriteBuffer()
write_json_value(buf, cast(JsonValue, values))
return {"platform": platform_opt, "other_options": hash_digest(buf.getvalue())}
cache = manager.options_snapshot_cache
cached = cache.get(cloned)
if cached is None:
platform_opt, values = cloned.select_options_affecting_cache()
buf = WriteBuffer()
write_json_value(buf, cast(JsonValue, values))
cached = (platform_opt, hash_digest(buf.getvalue()))
cache[cloned] = cached
return {"platform": cached[0], "other_options": cached[1]}


def find_cache_meta(
Expand Down
Loading

Back | FazBrowse Home | New Git URL