Skip to content

Commit a74e783

Browse files
chandlerokclaude
andcommitted
perf: Stamp SQL and Snowflake registry protos with a content-hash version_id
SqlRegistry.proto() and SnowflakeRegistry.proto() never set version_id, so the version-keyed caches fell back to object identity and every cache refresh still rebuilt every object from proto. Set version_id to the sha1 of the deterministic serialization, which is stable across refreshes and changes on any apply or delete. On a 421 KB registry proto the hash costs 0.2 ms. Refs feast-dev#7072 Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Chandler King <[email protected]>
1 parent 7deb605 commit a74e783

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎sdk/python/feast/infra/registry/snowflake.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import hashlib
12
import logging
23
import os
34
import uuid
@@ -1367,6 +1368,7 @@ def process_project(project: Project):
13671368
if last_updated_timestamps:
13681369
r.last_updated.FromDatetime(max(last_updated_timestamps))
13691370

1371+
r.version_id = hashlib.sha1(r.SerializeToString(deterministic=True)).hexdigest()
13701372
return r
13711373

13721374
def _get_last_updated_metadata(self, project: str):

‎sdk/python/feast/infra/registry/sql.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import hashlib
12
import logging
23
import uuid
34
from concurrent.futures import ThreadPoolExecutor
@@ -1570,6 +1571,7 @@ def process_project(project: Project):
15701571
if last_updated_timestamps:
15711572
r.last_updated.FromDatetime(max(last_updated_timestamps))
15721573

1574+
r.version_id = hashlib.sha1(r.SerializeToString(deterministic=True)).hexdigest()
15731575
return r
15741576

15751577
def commit(self):

‎sdk/python/tests/unit/infra/registry/test_sql_registry.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,3 +731,39 @@ def test_schema_mode_invalid_value_rejected(self):
731731
path="sqlite:///dummy.db",
732732
schema_mode="bogus",
733733
)
734+
735+
736+
def test_proto_version_id_is_a_content_hash(shared_sqlite_db_path):
737+
from unittest.mock import patch
738+
739+
from feast.feature_service import FeatureService
740+
741+
config = SqlRegistryConfig(
742+
registry_type="sql",
743+
path=f"sqlite:///{shared_sqlite_db_path}",
744+
purge_feast_metadata=False,
745+
)
746+
registry = SqlRegistry(config, "project_hash", None)
747+
registry.apply_feature_service(
748+
FeatureService(name="svc", features=[]), "project_hash"
749+
)
750+
751+
first = registry.proto()
752+
second = registry.proto()
753+
assert first.version_id
754+
assert first.version_id == second.version_id
755+
assert first is not second
756+
757+
with patch.object(
758+
FeatureService, "from_proto", wraps=FeatureService.from_proto
759+
) as from_proto:
760+
registry.refresh("project_hash")
761+
a = registry.get_feature_service("svc", "project_hash", allow_cache=True)
762+
registry.refresh("project_hash")
763+
b = registry.get_feature_service("svc", "project_hash", allow_cache=True)
764+
assert a is b
765+
from_proto.assert_called_once()
766+
767+
registry.apply_entity(Entity(name="customer", join_keys=["cid"]), "project_hash")
768+
assert registry.proto().version_id != first.version_id
769+
registry.teardown()

0 commit comments

Comments
 (0)