Repository navigation
Cache table refs - #2441
Cache table refs#2441
Conversation
|
Note: it's not clear why |
Codecov Report
@@ Coverage Diff @@
## main #2441 +/- ##
==========================================
- Coverage 93.43% 93.43% -0.01%
==========================================
Files 28 28
Lines 27347 27337 -10
Branches 1253 1247 -6
==========================================
- Hits 25551 25541 -10
Misses 1762 1762
Partials 34 34
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
40cfe83 to
7b4bcac
Compare
|
Current version means we parse the metadata schema every time we decode a row, so this will be very bad for row-access performance. |
7b4bcac to
912f047
Compare
|
Actually, I think the performance of this is fine. Here's my benchmark: import time
import tskit
import msprime
demography = msprime.Demography.stepping_stone_model([100] * 100, migration_rate=0.0)
for k in range(100):
demography[k].name = f"awesome_pop_{k}"
demography[k].description = "This population is totally awesome"
demography[k].extra_metadata = {f"x_{j}": list(range(j)) for j in range(100)}
ts = msprime.sim_ancestry({0: 2}, demography=demography, random_seed=1)
# print(ts.tables.populations)
before = time.perf_counter()
for _ in range(100):
for pop in ts.populations():
# print(pop.metadata)
# x = pop.metadata
pass
duration = time.perf_counter() - before
print(f"ts.populations in {duration:.2g} seconds")
# print(ts.tables.populations)
before = time.perf_counter()
for _ in range(100):
for pop in ts.populations():
# print(pop.metadata)
x = pop.metadata
pass
duration = time.perf_counter() - before
print(f"ts.populations decode metadata in {duration:.2g} seconds")
tables = ts.tables
# print(ts.tables.populations)
before = time.perf_counter()
for _ in range(100):
for pop in tables.populations:
# print(pop.metadata)
# x = pop.metadata
pass
duration = time.perf_counter() - before
print(f"tables.populations in {duration:.2g} seconds")
tables = ts.tables
# print(ts.tables.populations)
before = time.perf_counter()
for _ in range(100):
for pop in tables.populations:
# print(pop.metadata)
x = pop.metadata
pass
duration = time.perf_counter() - before
print(f"tables.populations decode metadata in {duration:.2g} seconds")For upstream/main we get: For this branch we get: So, there's no difference really when we're decoding significant amounts of metadata. The reason it doesn't matter that we're not caching the parsed metadata schema is because we have a functools.lru_cache on the What do you think @benjeffery - should we try other benchmarks here? |
912f047 to
6ed4aa0
Compare
|
Ahhh, interesting. The LRU cache was added to improve replicate performance after the initial TableCollection metadata implementation that has the instance-level cache. I think we can completely remove the instance level caching with little penalty then. I'll review this now. |
Closes tskit-dev#2439 Removes the caching layer for metadata schemas as it was causing consistency problems and wasn't doing anything in the most common case anyway (accessing tables.individuals, e.g.)
6ed4aa0 to
dd1d24c
Compare
Stacked on #2439
Closes #2080
Rather than creating new references each time we access
tables.edges, this caches the objects in TableCollection. There were a few things that tripped me up along the way, but I think it does lead to simpler code and makes it fairly clear now how we addess (part of, at least) makingts.tablesreturn a view of the TableCollection data.Benchmarks:
NOTE: the last two run 10x fewer iterations as
ts.tablesis still slowwww.Results
Current upstream main
This branch