Skip to content

Remove circular references in Table classes - #2434

Closed
benjeffery wants to merge 1 commit into
tskit-dev:mainfrom
benjeffery:fix_circular
Closed

benjeffery wants to merge 1 commit into
tskit-dev:mainfrom
benjeffery:fix_circular

Conversation

@benjeffery

Copy link
Copy Markdown
Member

For discussion with respect to #2431 and #2428.
The high memory usage in the loop in #2428 is resolved if gc.collect() is called in the loop. This indicates that a circular reference is at fault. This reference is due to the attribute replacement in MetadataColumnMixin.__init__ which results in the closure method being held in the dictionary of each table instance. I haven't traced the full cycle from there, but the closure holds lots of references.
This PR does a small refactor to make BaseTable check for additional arguments to the row constructor, in this way the instance attribute doesn't need to be rewritten and the circular reference and the excessive memory usage are gone.

I've only done a quick proof here - this could probably be done in a cleaner way.

@codecov

codecov Bot commented Jul 23, 2022 •

Copy link
Copy Markdown

Codecov Report

Merging #2434 (6e22ca5) into main (8b3322d) will decrease coverage by 3.46%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2434      +/-   ##
==========================================
- Coverage   93.32%   89.85%   -3.47%     
==========================================
  Files          28       28              
  Lines       26905    29270    +2365     
  Branches     1234     1859     +625     
==========================================
+ Hits        25108    26301    +1193     
- Misses       1763     2905    +1142     
- Partials       34       64      +30     
Flag Coverage Δ
c-tests 92.25% <ø> (ø)
lwt-tests 89.05% <ø> (ø)
python-c-tests 71.05% <100.00%> (+<0.01%) ⬆️
python-tests 98.93% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
python/tskit/tables.py 92.33% <100.00%> (-6.60%) ⬇️
python/tskit/combinatorics.py 71.96% <0.00%> (-27.40%) ⬇️
python/tskit/trees.py 76.35% <0.00%> (-22.28%) ⬇️
python/tskit/genotypes.py 80.00% <0.00%> (-18.47%) ⬇️
python/tskit/drawing.py 98.99% <0.00%> (-0.19%) ⬇️
python/tskit/__init__.py 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b3322d...6e22ca5. Read the comment docs.

@benjeffery

Copy link
Copy Markdown
Member Author

Closed in favour of #2439

@benjeffery benjeffery closed this Jul 27, 2022
@benjeffery
benjeffery deleted the fix_circular branch July 27, 2022 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant