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

Delete input chunks after compute method to save memory #942

Merged
merged 5 commits into from
Dec 24, 2024

Conversation

dachengx
Copy link
Collaborator

@dachengx dachengx commented Dec 22, 2024

This will lower the memory usage of st.make(run_id, 'peaklets') of XENONnT by 1 / 6, if set clean_chunk_after_compute = True.

Note: https://xe1t-wiki.lngs.infn.it/doku.php?id=xenon:xenonnt:straxen:optimize_outsource_resources#optimized_memory_usage

@coveralls
Copy link

coveralls commented Dec 22, 2024

Coverage Status

coverage: 89.139% (-0.06%) from 89.201%
when pulling 2465e43 on del_input_chunks
into 2ed84f9 on master.

@dachengx dachengx marked this pull request as ready for review December 22, 2024 22:21
@@ -206,9 +206,9 @@ def split(self, t: ty.Union[int, None], allow_early_split=False):
"""
t = max(min(t, self.end), self.start) # type: ignore
if t == self.end:
data1, data2 = self.data, self.data[:0]
data1, data2 = self.data, self.data[:0].copy()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is to prevent the reference build between data2 and self.data to make sure that the sys.getrefcount(data) is low enough.

_kwargs["start"] = start
_kwargs["end"] = end
result = self.compute(**_kwargs)
del _kwargs
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Delete _kwargs because it will keep a reference between _kwargs and kwargs[k].data.

f"Reference count of input {k} is {n} "
"and should be 1. This is a memory leak."
)
del kwargs[k].data
Copy link
Collaborator Author

@dachengx dachengx Dec 23, 2024

Choose a reason for hiding this comment

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

You might see AttributeError when calling kwargs[k] which is a strax.Chunk after this deletion. So do not delete if you really want to reuse kwargs[k], though this is very discouraged.

@dachengx dachengx merged commit b97cad2 into master Dec 24, 2024
8 checks passed
@dachengx dachengx deleted the del_input_chunks branch December 24, 2024 00:05
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.

2 participants