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

perf: removing output arrays from reference cycles so they don't have to wait for GC #1305

Merged
23 changes: 18 additions & 5 deletions src/uproot/behaviors/TBranch.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,16 @@ def iterate(
arrays, report = item
arrays = library.global_index(arrays, global_offset)
report = report.to_global(global_offset)
yield arrays, report
popper = [arrays]
del arrays
del item
yield popper.pop(), report

else:
arrays = library.global_index(item, global_offset)
yield arrays
popper = [library.global_index(item, global_offset)]
del item
yield popper.pop()

except uproot.exceptions.KeyInFileError:
if allow_missing:
continue
Expand Down Expand Up @@ -1111,6 +1117,9 @@ def iterate(
ak_add_doc,
)

# no longer needed; save memory
del output

next_baskets = {}
for branch, basket_num, basket in ranges_or_baskets:
basket_entry_start, basket_entry_stop = basket.entry_start_stop
Expand All @@ -1119,10 +1128,14 @@ def iterate(

previous_baskets = next_baskets

# no longer needed; save memory
popper = [out]
del out

if report:
yield out, Report(self, sub_entry_start, sub_entry_stop)
yield popper.pop(), Report(self, sub_entry_start, sub_entry_stop)
else:
yield out
yield popper.pop()

def keys(
self,
Expand Down
4 changes: 4 additions & 0 deletions src/uproot/language/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,10 @@ def getter(name):
else:
output[name] = output[name][cut]

# clear dicts to get rid of big arrays.
# note: without this these arrays are not properly released from memory!
values.clear()
scope.clear()
return output


Expand Down
Loading