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

Core: fix some memory leak sources without removing caching #2400

Merged
merged 6 commits into from
Oct 31, 2023

Conversation

black-sliver
Copy link
Member

Supersedes #2399

Use of @Utils.cache_self1 gives a "Parameter(s) unfilled" on call site in pycharm, but mypy claims it's fine. If anyone knows if we can fix that, please let me know.

Maybe @el-u with the typing experience.

@ThePhar ThePhar added is: bug/fix Issues that are reporting bugs or pull requests that are fixing bugs. affects: core Issues/PRs that touch core and may need additional validation. labels Oct 29, 2023
@Berserker66
Copy link
Member

image
This is in a multiworld with a yaml of each game, except sudoku and ff1

Copy link
Member

@Berserker66 Berserker66 left a comment

Choose a reason for hiding this comment

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

With just Subnautica it now deallocates the multiworld as desired. Remaining culripits are probably in the world folders. Don't know if that should be adressed in this PR or a follow-up, but as is, this PR is an improvement.

@black-sliver
Copy link
Member Author

I'd like to see if someone can figure out the pycharm linter error.

Two things to check in the meantime are
if cached_property is fine or not, and
if the culprit is Zillion, since that has an internal cache.

If you beat me to it, feel free to push to my branch.

@Berserker66
Copy link
Member

cached_property was hit during the Subnautica run which did de-allocate. To make sure I just did:
image
And that too de-allocates.

@Berserker66
Copy link
Member

genning with just zillion also de-allocates.

@el-u
Copy link
Collaborator

el-u commented Oct 29, 2023

I'm not seeing "Parameter(s) unfilled" on the new code in BaseClasses.

@black-sliver
Copy link
Member Author

It highlights the closing ) on line 1235, for example, and when I hover it, i get this
error

@Berserker66
Copy link
Member

I think that's what's solved with typing.Self on newer python.

@el-u
Copy link
Collaborator

el-u commented Oct 29, 2023

It highlights the closing ) on line 1235, for example, and when I hover it, i get this

I see. Honestly, this could be a PyCharm issue. The typing seems correct.

@black-sliver
Copy link
Member Author

I think that's what's solved with typing.Self on newer python.

I don't think so, because PyCharm claims the number of arguments is wrong, not the type.

Honestly, this could be a PyCharm issue.

There are a couple of issues open for PyCharm with decorator and typing, so it's very likely. Typing also looks correct to mypy and me.

@Berserker66
Copy link
Member

Find which issue it is and leave a comment... on both ends, I'd say.

@el-u
Copy link
Collaborator

el-u commented Oct 29, 2023

Can you make a test that creates a multiworld for each world type and checks whether it can be deallocated?

@black-sliver
Copy link
Member Author

black-sliver commented Oct 30, 2023

Can you make a test that creates a multiworld for each world type and checks whether it can be deallocated?

  • We could check for memory leak as part of test.bases.WorldTestBase.tearDown, however that should probably be limited to once per class, because gc.collect() is expensive - i.e. tearDownClass should run for the last one, I think. We can also only warn there I think, but it would then test all option combinations for worlds that define tests.

  • We could create a generic test (like the ones test_reachability.py) that asserts memory is free'd, however that would only run for default options.

  • We could do both, and skip the tearDown one for options == {}

@black-sliver
Copy link
Member Author

Maybe like this @el-u ?

@Berserker66
Copy link
Member

Berserker66 commented Oct 30, 2023

Are we sure the current test failures now are accurate? It not leaking on 3.11 feels odd.

@el-u
Copy link
Collaborator

el-u commented Oct 30, 2023

Are we sure the current test failures now are accurate? It not leaking on 3.11 feels odd.

No. I'd say the test failures are not understood. It fails for worlds that deallocate properly when just running generate. Could be that there's something wrong with the test. Failing worlds are basically LADX + Minecraft + those that use the new options system; but unsure whether that has anything to do with it.

@black-sliver
Copy link
Member Author

Those failure are bogus and only happen on py<3.11. I've been trying to figure out why, but I hit a dead end again. The references to the MultiWorld are all regions, but I am not sure where they are referenced - I'm afraid that might be somewhere inside unittest? An assertion or a subtest maybe?

I think I'll just disable the failing ones for <3.11 for now and leave a comment. The generic (default options) test still works for those at least.

@black-sliver black-sliver merged commit 5f5c48e into ArchipelagoMW:main Oct 31, 2023
@black-sliver black-sliver deleted the core_memory_leaks2 branch October 31, 2023 01:09
black-sliver added a commit to black-sliver/Archipelago that referenced this pull request Nov 2, 2023
black-sliver added a commit to black-sliver/Archipelago that referenced this pull request Nov 2, 2023
black-sliver added a commit that referenced this pull request Nov 2, 2023
FlySniper pushed a commit to FlySniper/Archipelago that referenced this pull request Nov 14, 2023
…lagoMW#2400)

* Core: fix some memory leak sources

* Core: run gc before detecting memory leaks

* Core: restore caching in BaseClasses.MultiWorld

* SM: move spheres cache to MultiWorld._sm_spheres to avoid memory leak

* Test: add tests for world memory leaks

* Test: limit WorldTestBase leak-check to py>=3.11

---------

Co-authored-by: Fabian Dill <[email protected]>
FlySniper pushed a commit to FlySniper/Archipelago that referenced this pull request Nov 14, 2023
Jouramie pushed a commit to Jouramie/Archipelago that referenced this pull request Feb 28, 2024
…lagoMW#2400)

* Core: fix some memory leak sources

* Core: run gc before detecting memory leaks

* Core: restore caching in BaseClasses.MultiWorld

* SM: move spheres cache to MultiWorld._sm_spheres to avoid memory leak

* Test: add tests for world memory leaks

* Test: limit WorldTestBase leak-check to py>=3.11

---------

Co-authored-by: Fabian Dill <[email protected]>
Jouramie pushed a commit to Jouramie/Archipelago that referenced this pull request Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects: core Issues/PRs that touch core and may need additional validation. is: bug/fix Issues that are reporting bugs or pull requests that are fixing bugs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants