You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
2 - Avoid recreating full table mapping for every render #6018
Issue is really in sqlmesh/core/renderer.py in _resolve_tables that we touched in Issue 1. The function calls to_table_mapping for every expression, doing a comprehension every single time. We need to cache the mapping so renders just grab the cache instead of recreating it.
Example AI Code
_TO_TABLE_MAPPING_CACHE: dict[tuple, dict[str, str]] = {}
def to_table_mapping(
snapshots: t.Iterable[Snapshot], deployability_index: t.Optional[DeployabilityIndex]
) -> t.Dict[str, str]:
snapshots = list(snapshots)
deployability_index = deployability_index or DeployabilityIndex.all_deployable()
key = (
deployability_index.indexed_ids,
deployability_index.is_opposite_index,
deployability_index.representative_shared_version_ids,
tuple((s.snapshot_id, s.version, s.dev_version) for s in snapshots),
)
cached = _TO_TABLE_MAPPING_CACHE.get(key)
if cached is None:
cached = {
snapshot.name: snapshot.table_name(deployability_index.is_deployable(snapshot))
for snapshot in snapshots
if snapshot.version and not snapshot.is_embedded and snapshot.is_model
}
_TO_TABLE_MAPPING_CACHE[key] = cached
return dict(cached)
Note: lru_cache on the function directly does not work — snapshots is an unhashable iterable of objects.
Cleaner approach is caching this all the way up inside SnapshotEvaluator.promote -- sqlmesh/core/snapshot/evaluator.py and pass into _promote_snapshot so the cache is not created per thread. Either is acceptable right now, just if you want to increase scope.
Activity
cmgoffena13 commentedon Sep 3, 2026
Cleaner approach is caching this all the way up inside
SnapshotEvaluator.promote--sqlmesh/core/snapshot/evaluator.pyand pass into_promote_snapshotso the cache is not created per thread. Either is acceptable right now, just if you want to increase scope.