Commit 2b1fb0e
committed
perf: Cache Transaction.table_metadata between staged updates
Transaction.table_metadata calls update_table_metadata on every
access, which replays every staged update through
model_copy(deep=True). Code that reads the property repeatedly
within a single logical operation (e.g. the snapshot producer's
schema()/spec()/new_manifest_writer() helpers inside per-manifest
loops) pays that cost each time.
This caches the result keyed on the identity of the base metadata
and the staged-updates tuple. Since _updates is an immutable tuple,
every self._updates += (...) rebinds it to a new object, so the
identity check self-invalidates without any explicit cache-clearing
at mutation sites. The cache also invalidates when the underlying
Table.metadata is refreshed after a commit.
The only observable difference is that last_updated_ms on the
returned metadata is now stable across repeated reads of the same
logical state, instead of being re-stamped with now() on each
access. The timestamp written at commit time is unaffected.
Adds a test that asserts repeated reads compute once, and that
staging an update invalidates and recomputes.1 parent e6d5129 commit 2b1fb0e
2 files changed
Lines changed: 44 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| 214 | + | |
214 | 215 | | |
215 | 216 | | |
216 | 217 | | |
| |||
223 | 224 | | |
224 | 225 | | |
225 | 226 | | |
| 227 | + | |
226 | 228 | | |
227 | 229 | | |
228 | 230 | | |
229 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
230 | 242 | | |
231 | 243 | | |
232 | 244 | | |
| |||
1961 | 1973 | | |
1962 | 1974 | | |
1963 | 1975 | | |
1964 | | - | |
1965 | | - | |
1966 | | - | |
1967 | | - | |
1968 | | - | |
1969 | | - | |
1970 | | - | |
| 1976 | + | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
1971 | 1981 | | |
1972 | 1982 | | |
1973 | 1983 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1766 | 1766 | | |
1767 | 1767 | | |
1768 | 1768 | | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
0 commit comments