Repository navigation
perf: Key registry proto caches on version_id so a refresh does not rebuild objects #7073
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
base: master
Are you sure you want to change the base?
Changes from all commits
7deb605
a74e783
87deb2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,11 @@ | |
| # that leave version_id empty (SqlRegistry) then read another registry's objects. | ||
|
|
||
|
|
||
| def _registry_proto_key(registry_proto: RegistryProto): | ||
| """Return the registry's version_id, or the object identity when it has none.""" | ||
| return registry_proto.version_id or id(registry_proto) | ||
|
|
||
|
|
||
| def registry_proto_cache(func): | ||
| cache_proto = None | ||
| cache_key = None | ||
|
|
@@ -42,7 +47,7 @@ def registry_proto_cache(func): | |
| def wrapper(registry_proto: RegistryProto, project: str): | ||
| nonlocal cache_proto, cache_key, cache_value | ||
|
|
||
| key = (registry_proto.version_id, project) | ||
| key = (_registry_proto_key(registry_proto), project) | ||
|
|
||
| if registry_proto is cache_proto and key == cache_key: | ||
| return cache_value | ||
|
|
@@ -72,7 +77,7 @@ def wrapper( | |
| # Snapshot the filter so caller mutations cannot change a cached key. | ||
| tags_key = frozenset(tags.items()) if tags is not None else None | ||
| key = ( | ||
| registry_proto.version_id, | ||
| _registry_proto_key(registry_proto), | ||
| project, | ||
| tags_key, | ||
| kwargs_key, | ||
|
|
@@ -95,7 +100,9 @@ def registry_proto_cache_name(func): | |
|
|
||
| @wraps(func) | ||
| def wrapper(registry_proto: RegistryProto, name: str, project: str): | ||
| nonlocal cache_proto, cache_version, cache | ||
| nonlocal cache_proto_key, cache | ||
|
Member
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.
|
||
|
|
||
| proto_key = _registry_proto_key(registry_proto) | ||
|
|
||
| if ( | ||
| registry_proto is not cache_proto | ||
|
|
@@ -126,6 +133,7 @@ def get_project_metadata( | |
| return None | ||
|
|
||
|
|
||
| @registry_proto_cache_name | ||
| def get_feature_service( | ||
| registry_proto: RegistryProto, name: str, project: str | ||
| ) -> FeatureService: | ||
|
|
||
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.
the cache-hit condition below still requires
registry_proto is cache_proto, so parsing a new proto with the same version always misses. the same identity check remains inregistry_proto_cache; changing the key alone does not deliver the refresh reuse described by this PR, and the added same-version test cannot pass. we should compare the version-based key for versioned registries while retaining a strong object-identity guard for registries without a version.