Skip to content

PERF: Break reference cycle for all Index types #27840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 14, 2019

Conversation

topper-123
Copy link
Contributor

@topper-123 topper-123 commented Aug 9, 2019

Generalizes the test in #27607 to be used for all index types. This finds ref cycle issues for PeriodIndex and CategoricalIndex which are solved in this PR.

@topper-123 topper-123 added Index Related to the Index class or subclasses Performance Memory or execution speed performance labels Aug 9, 2019
Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomAugspurger TomAugspurger added this to the 0.25.1 milestone Aug 9, 2019
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good -
question and comment

@@ -441,7 +442,9 @@ def _formatter_func(self):

@cache_readonly
def _engine(self):
return self._engine_type(lambda: self, len(self))
# To avoid a reference cycle, pass a weakref of self to _engine_type.
period = weakref.ref(self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we be using weakref in the other invocations for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weakrefs cause some tests to fail.

I'm not sure currently if those failures are correct, could be worth an investigation. @crepererum , did you investigate if weakrefs not working is the correct behaviour?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I didn't test this.

IMHO, the weakref isn't required in the other cases since we're passing a member of self and not self itself. Using a weakref seemed to make things only unnecessary complicated, since then you have just a chain of indirections (lambda->scope->weakref->self->member instead of lambda->scope->member).

@crepererum
Copy link
Contributor

crepererum commented Aug 12, 2019

Thanks for providing this extended fix :)

@topper-123 topper-123 force-pushed the breaf_index_ref_cycles branch from 86bf0fe to 36061a1 Compare August 14, 2019 08:55
@topper-123
Copy link
Contributor Author

I think this should be ok to pull in after the rebase?

@TomAugspurger
Copy link
Contributor

Agreed, thanks!

@TomAugspurger TomAugspurger merged commit fae56d0 into pandas-dev:master Aug 14, 2019
meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Aug 14, 2019
@topper-123 topper-123 deleted the breaf_index_ref_cycles branch August 14, 2019 21:52
quintusdias pushed a commit to quintusdias/pandas_dev that referenced this pull request Aug 16, 2019
* Generalize guards for index ref cycles

* add issue number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Index Related to the Index class or subclasses Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants