-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve memory efficiency by discarding references to objects immedia…
…tely When "killing" or "removing" elements from a tree, it's important not to keep references to them in the lists where they're collected. Without this, the memory consumption was quadratic because the tails in this case were combined into parents'/previous' elements' tails and the original ones could not be removed as we kept the references to the elements in the _kill and _remove lists. For more info see: https://bugs.launchpad.net/lxml/+bug/1889653 Co-authored-by: Miro Hrončok <miro@hroncok.cz>
- Loading branch information
1 parent
da9d66c
commit 89b2b3d
Showing
4 changed files
with
45 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import unittest | ||
|
||
|
||
def peak_memory_usage(func, *args, **kwargs): | ||
""" | ||
Monitor the memory usage of a function and return the peak memory used, in MiB. | ||
""" | ||
try: | ||
from memory_profiler import memory_usage # type: ignore | ||
except ImportError: | ||
raise unittest.SkipTest("memory-profiler is not available") | ||
|
||
try: | ||
mem_usage = memory_usage((func, args, kwargs), interval=0.1, timeout=None) | ||
except MemoryError: | ||
return float("inf") | ||
peak_memory = max(mem_usage) - min(mem_usage) | ||
return peak_memory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters