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

Create a CacheManager class to manage storing and clearing caches #1782

Merged
merged 3 commits into from Sep 17, 2022

Conversation

DanielNoord
Copy link
Collaborator

@DanielNoord DanielNoord commented Sep 15, 2022

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

Refs. #1780

Another attempt after #1781. Results are the same 🎉

@matusvalo would you be able to test this change?
@jacobtylerwalls Does this seem like a reasonable design to you?

Type of Changes

Type
🐛 Bug fix

Details

I use the following script to check for the leakage of NodeNG objects.

from io import StringIO

from pylint.lint import Run, pylinter
from pylint.reporters.text import TextReporter
from pympler import muppy, summary

from astroid import nodes


def get_memory_info(
    should_count_nodes: bool = False, should_tracemalloc: bool = False
) -> None:
    prev_nodes = 0

    for round in range(5):
        # Node counting setup
        count_nodes = 0

        # Run program
        Run(
            ["astroid/nodes/node_ng.py"],
            exit=False,
            reporter=TextReporter(StringIO()),
        )
        # Clear cache
        pylinter.MANAGER.clear_cache()

        # Node counting
        if should_count_nodes:
            for o in muppy.get_objects():
                if isinstance(o, nodes.NodeNG):
                    count_nodes += 1

            print()
            print("Nodes INC:", count_nodes - prev_nodes)
            prev_nodes = count_nodes
            print("Nodes NEW:", prev_nodes)



get_memory_info(should_count_nodes=True)

On main this returns:

Nodes INC: 132313
Nodes NEW: 132313

Nodes INC: 93202
Nodes NEW: 225515

Nodes INC: 92207
Nodes NEW: 317722

Nodes INC: 92147
Nodes NEW: 409869

Nodes INC: 92147
Nodes NEW: 502016

On this PR this returns:

Nodes INC: 105458
Nodes NEW: 105458

Nodes INC: 63140
Nodes NEW: 168598

Nodes INC: 58253
Nodes NEW: 226851

Nodes INC: 58193
Nodes NEW: 285044

Nodes INC: 58193
Nodes NEW: 343237

We're definitely still leaking, but it seems to be better at least.

I ran the pylint test suite and the time was around as I expect and similar to a run against main just before it. So I think the caching is also still working.

@coveralls
Copy link

coveralls commented Sep 15, 2022

Pull Request Test Coverage Report for Build 3059476368

  • 15 of 15 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 92.429%

Totals Coverage Status
Change from base Build 3042886225: 0.01%
Covered Lines: 9791
Relevant Lines: 10593

💛 - Coveralls

@DanielNoord DanielNoord added this to the 2.12.10 milestone Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants