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

Fix garbage collection #2754

Merged
merged 36 commits into from
Jun 18, 2022
Merged

Fix garbage collection #2754

merged 36 commits into from
Jun 18, 2022

Conversation

akaszynski
Copy link
Member

@akaszynski akaszynski commented Jun 8, 2022

First Problem: Unnecessary Scalar Array Copying

As pointed out, we're copying scalars within add_mesh. When plotting existing scalars with:

import pyvista
mesh = pyvista.Sphere()
mesh['data'] = range(mesh.n_points)
mesh.plot(scalars='data')

We actually create a copy of the scalars:

# Scalars interpolation approach
if use_points:
mesh.point_data.set_array(scalars, title, True)
mesh.active_scalars_name = title
self.SetScalarModeToUsePointData()
elif use_cells:
mesh.cell_data.set_array(scalars, title, True)
mesh.active_scalars_name = title
self.SetScalarModeToUseCellData()
else:
raise_not_matching(scalars, mesh)

This is inefficient, but this actually protects us from underlying garbage collection issues.


Second Problem: Garbage Collection of VTK Arrays

When performing a shallow copy, we end up with a VTK array memory leak. This can be reproduced with:

import pyvista
mesh = pyvista.Sphere()
mesh.point_data['data'] = range(mesh.n_points)
mesh.point_data['data'] = mesh.point_data['data']

This issue is caused by us recreating the pointer to the underlying VTK array, and the old pointer is not discarded. The solution to this is to simply reuse the underlying pointer.


Requires #2770

Bonus changes

  • Refactored set_scalars use of configure_scalars_mode as we were calling that twice when setting scalars for custom opacity.

@github-actions github-actions bot added the bug Uh-oh! Something isn't working as expected. label Jun 8, 2022
@codecov
Copy link

codecov bot commented Jun 8, 2022

Codecov Report

Merging #2754 (cbc95ca) into main (a3d0351) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #2754      +/-   ##
==========================================
- Coverage   93.97%   93.94%   -0.04%     
==========================================
  Files          76       76              
  Lines       16320    16348      +28     
==========================================
+ Hits        15337    15358      +21     
- Misses        983      990       +7     

pyvista/core/datasetattributes.py Outdated Show resolved Hide resolved
pyvista/core/datasetattributes.py Outdated Show resolved Hide resolved
tests/plotting/test_collection.py Outdated Show resolved Hide resolved
tests/plotting/test_collection.py Outdated Show resolved Hide resolved
tests/plotting/test_plotting.py Outdated Show resolved Hide resolved
tests/test_utilities.py Outdated Show resolved Hide resolved
tests/test_utilities.py Outdated Show resolved Hide resolved
tests/test_utilities.py Outdated Show resolved Hide resolved
pyvista/plotting/mapper.py Outdated Show resolved Hide resolved
pyvista/plotting/mapper.py Outdated Show resolved Hide resolved
pyvista/_vtk.py Outdated Show resolved Hide resolved
pyvista/utilities/helpers.py Outdated Show resolved Hide resolved
tests/test_utilities.py Outdated Show resolved Hide resolved
akaszynski and others added 12 commits June 12, 2022 08:36
Co-authored-by: Andras Deak <adeak@users.noreply.github.com>
* Update information of translation project

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* Update doc/index.rst

Co-authored-by: Alex Kaszynski <akascap@gmail.com>
Co-authored-by: Andras Deak <adeak@users.noreply.github.com>
Updates the requirements on [hypothesis](https://github.com/HypothesisWorks/hypothesis) to permit the latest version.
- [Release notes](https://github.com/HypothesisWorks/hypothesis/releases)
- [Commits](HypothesisWorks/hypothesis@hypothesis-ruby-0.0.1...hypothesis-python-6.47.1)

---
updated-dependencies:
- dependency-name: hypothesis
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: akaszynski <akaszynski@users.noreply.github.com>
* Add generate_polygon arg to Polygon

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: Andras Deak <adeak@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Andras Deak <adeak@users.noreply.github.com>
* skip or avoid creating files in doc build

* remove mention of _get_default_tempdir
* Create codeql-analysis.yml

* Update README.rst

* Update app.py

* Fix by isort

* Delete codeql-analysis.yml

* Apply suggestions from code review
* Add extrude-trim.py

* Add example comment

* Add test

* Add an inplace test

* Add extrude_trim filter

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* Update pyvista/core/filters/poly_data.py

Co-authored-by: Phil Chiu <whophil@users.noreply.github.com>

* Apply suggestions from code review

* Fix by black

* Fix by isort

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: MatthewFlamm <39341281+MatthewFlamm@users.noreply.github.com>

* improve example

Co-authored-by: Phil Chiu <whophil@users.noreply.github.com>
Co-authored-by: MatthewFlamm <39341281+MatthewFlamm@users.noreply.github.com>
Co-authored-by: Alex Kaszynski <akascap@gmail.com>
Updates the requirements on [hypothesis](https://github.com/HypothesisWorks/hypothesis) to permit the latest version.
- [Release notes](https://github.com/HypothesisWorks/hypothesis/releases)
- [Commits](HypothesisWorks/hypothesis@hypothesis-ruby-0.0.1...hypothesis-python-6.47.2)

---
updated-dependencies:
- dependency-name: hypothesis
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
MatthewFlamm and others added 4 commits June 14, 2022 01:19
* optionally fail when image is missing

* use in linux tests instead of windows

* remove failing test
* fix return types

* override __array_wrap__

* Apply suggestions from code review

* Update pyvista/core/pyvista_ndarray.py

Co-authored-by: Andras Deak <adeak@users.noreply.github.com>

Co-authored-by: Andras Deak <adeak@users.noreply.github.com>
@akaszynski
Copy link
Member Author

Ready for review @adeak.

pyvista/utilities/helpers.py Outdated Show resolved Hide resolved
pyvista/utilities/helpers.py Outdated Show resolved Hide resolved
pyvista/utilities/helpers.py Show resolved Hide resolved
pyvista/core/datasetattributes.py Outdated Show resolved Hide resolved
pyvista/core/datasetattributes.py Outdated Show resolved Hide resolved
pyvista/core/datasetattributes.py Outdated Show resolved Hide resolved
pyvista/utilities/helpers.py Outdated Show resolved Hide resolved
pyvista/core/datasetattributes.py Outdated Show resolved Hide resolved
@akaszynski
Copy link
Member Author

@adeak, we're ready for review (again).

Copy link
Member

@adeak adeak left a comment

Choose a reason for hiding this comment

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

Approving the earlier changes, but @akaszynski please check mine before merging (assuming CI ends up green).

pyvista/utilities/helpers.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Uh-oh! Something isn't working as expected.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants