Skip to content
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

Cache ancestors #1120

Closed
wants to merge 6 commits into from
Closed

Cache ancestors #1120

wants to merge 6 commits into from

Conversation

dwo
Copy link

@dwo dwo commented Aug 7, 2021

Steps

  • For new features or bug fixes, add a ChangeLog entry describing what your PR does.
  • Write a good description on what the PR does.

Description

Type of Changes

Type
βœ“ πŸ› Bug fix
βœ“ ✨ New feature
βœ“ πŸ”¨ Refactoring
βœ“ πŸ“œ Docs

Related Issue

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Thank you for that, if we believe the graph given in #1115 (comment) this is gonna be a huge performance boost. Could we check that this is really a performance boost, please ?

@@ -1040,7 +1040,7 @@ class Past(Present):
astroid = builder.parse(data)
past = astroid["Past"]
attr = past.getattr("attr")
self.assertEqual(len(attr), 1)
self.assertEqual(len(attr), 1, attr)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self.assertEqual(len(attr), 1, attr)
assert len(attr) == 1

I think when using pytest this is possible (?)

Copy link
Author

Choose a reason for hiding this comment

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

Any Ideas why this might have started failing though? I had a read through getattr but since it doesn't call ancestors directly I'm going to need to dig a little more.

Copy link
Author

Choose a reason for hiding this comment

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

on main, attr is...

[<AssignName.attr l.3 at 0x[...]>]

with my changes this becomes...

[<AssignName.attr l.3 at 0x[...]>, <Const.int l.3 at 0x[...]>]

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

I suspect that using ClassDefs and InferenceContexts as keys was a bit naive: they aren't Singletons and don't implement __hash__ and __eq__ so I am only caching specific instances by object id instead of detecting when the ancestors or contexts are equivalent.

# FIXME: should be possible to choose the resolution order
# FIXME: inference make infinite loops possible here
yielded = {self}
yielded = OrderedDict()
Copy link
Author

Choose a reason for hiding this comment

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

I think this is necessary for Python 3.6 to preserve the order of yielded ancestors: a plain dict achieves the same thing from Python 3.7+

@dwo
Copy link
Author

dwo commented Aug 8, 2021

Thank you for that, if we believe the graph given in #1115 (comment) this is gonna be a huge performance boost. Could we check that this is really a performance boost, please ?

Once I get the tests to pass I want to try this against the example given in pylint-dev/pylint#4079 and then perhaps retry #1115 too.

Are there some codebases to run pylint against that make a good benchmark?

I also wondered if I should try and measure what the extra memory cost will be: I know there's prior art for this from https://rtpg.co/2020/10/12/pylint-usage.html

@DanielNoord
Copy link
Collaborator

@dwo Are you still interested in picking this PR back up or should we close it?

@dwo
Copy link
Author

dwo commented Jul 2, 2022

Damn, I forgot about this and would have liked to spend more time on it... will close for now.

@dwo dwo closed this Jul 2, 2022
@DanielNoord
Copy link
Collaborator

I still think this would indeed be very valuable. ancestors is one of the most expensive calls in regular pylint calls.

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.

3 participants