-
Notifications
You must be signed in to change notification settings - Fork 38
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
Conversation
@@ -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() |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
This will lower the memory usage of
st.make(run_id, 'peaklets')
of XENONnT by 1 / 6, if setclean_chunk_after_compute = True
.Note: https://xe1t-wiki.lngs.infn.it/doku.php?id=xenon:xenonnt:straxen:optimize_outsource_resources#optimized_memory_usage