Skip to content

Commit

Permalink
cache rendered Form and ImplementedFormMappingInfo
Browse files Browse the repository at this point in the history
restrict more stateful parts of code to client side of dask
  • Loading branch information
lgray committed Oct 18, 2023
1 parent 2f99815 commit 1f8c9a1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/uproot/_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ class UprootReadMixin:
base_form: Form
common_keys: frozenset[str]
interp_options: dict[str, Any]
_high_level_form_and_info: tuple[Form, ImplementsFormMappingInfo]

def read_tree(self, tree: HasBranches, start: int, stop: int) -> AwkArray:
assert start <= stop
Expand All @@ -898,7 +899,7 @@ def read_tree(self, tree: HasBranches, start: int, stop: int) -> AwkArray:
awkward = uproot.extras.awkward()
nplike = Numpy.instance()

form, form_info = self.form_mapping(self.base_form)
form, form_info = self._high_level_form_and_info

# The remap implementation should correctly populate the generated
# buffer mapping in __call__, such that the high-level form can be
Expand Down Expand Up @@ -939,7 +940,7 @@ def read_tree(self, tree: HasBranches, start: int, stop: int) -> AwkArray:

def mock(self) -> AwkArray:
awkward = uproot.extras.awkward()
high_level_form, form_info = self.form_mapping(self.base_form)
high_level_form, form_info = self._high_level_form_and_info
return awkward.typetracer.typetracer_from_form(
high_level_form,
highlevel=True,
Expand All @@ -952,7 +953,7 @@ def prepare_for_projection(self) -> tuple[AwkArray, TypeTracerReport, dict]:

# A form mapping will (may) remap the base form into a new form
# The remapped form can be queried for structural information
high_level_form, form_info = self.form_mapping(self.base_form)
high_level_form, form_info = self._high_level_form_and_info

# Build typetracer and associated report object
meta, report = awkward.typetracer.typetracer_with_report(
Expand Down Expand Up @@ -1026,6 +1027,7 @@ def __init__(
self.interp_options = interp_options
self.form_mapping = form_mapping
self.base_form = base_form
self._high_level_form_and_info = self.form_mapping(self.base_form)

def project_keys(self: T, keys: frozenset[str]) -> T:
return _UprootRead(
Expand Down Expand Up @@ -1056,6 +1058,7 @@ def __init__(
self.interp_options = interp_options
self.form_mapping = form_mapping
self.base_form = base_form
self._high_level_form_and_info = self.form_mapping(self.base_form)

def __call__(self, blockwise_args) -> AwkArray:
(
Expand Down

0 comments on commit 1f8c9a1

Please sign in to comment.