-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[WIP] Memoize the options snapshot #21354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
KevinRK29
wants to merge
1
commit into
python:master
Choose a base branch
from
KevinRK29:options-snapshot-memoize
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+20
−6
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
|---|---|---|
|
|
@@ -993,6 +993,11 @@ 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 id() of the cloned Options. | ||
| # Most modules share a handful of distinct configs. The keepalive | ||
| # list keeps clones reachable so id() is stable for cache keys. | ||
| self.options_snapshot_cache: dict[int, tuple[str, str]] = {} | ||
| self._options_snapshot_keepalive: list[Options] = [] | ||
| # Packages for which we know presence or absence of __getattr__(). | ||
| self.known_partial_packages: dict[str, bool] = {} | ||
|
|
||
|
|
@@ -1966,23 +1971,32 @@ 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 | ||
| key = id(cloned) | ||
| cached = cache.get(key) | ||
| 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[key] = cached | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think unstructured globs can never be cached, since they are always recreated, so the cache will never be hit (but I'm not 100% sure). |
||
| # Keep cloned reachable so its id() is not reused by a later clone. | ||
| manager._options_snapshot_keepalive.append(cloned) | ||
| return {"platform": cached[0], "other_options": cached[1]} | ||
|
|
||
|
|
||
| def find_cache_meta( | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use just
clonedas the key?