This repository has been archived by the owner on Jan 7, 2023. It is now read-only.
Optimize BetterChain::GetEntry to mimic the behavior of TTreeFormula. #162
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
At present,
BetterChain::GetEntry
usesTChain::GetEntry
, which calls down toTTree::GetEntry
. Unfortunately,TTree::GetEntry
iterates over ALL branches and callsTBranch::GetEntry
, and even thoughTBranch::GetEntry
is a no-op if the branch is not active, the iteration incurs considerable cost. This commit modifiesBetterChain::GetEntry
to manually iterate over only active branches and callTBranch::GetEntry
. This mimics the behavior ofTTreeFormula::EvalInstance
, which only callsTBranch::GetEntry
for required branches.Given that
BetterChain
already re-implements a large portion of the functionality ofTChain
, the code complexity added here is not egregious. In theTTree::GetEntry
documentation, manually callingTBranch::GetEntry
is even an officially sanctioned alternative. This optimization only affectsTTree
s with a large number of branches, but the performance increase is substantial.In tests on a
TTree
with 3,397,413 entries with 408 branches, I tried loading 14 branches of all entries usingroot2array
, and I saw the following load times:Without modification
Average: 11.924s
With modification
Average: 4.1168s
This is a ~2.9x speedup. While one might argue that this is a contrived case, the growing size and complexity of ntuples is going to make this type of tree more common, so I would argue that such an optimization is worth it. There is also 0 penalty to smaller trees, and even they will see some performance enhancement.
Unfortunately,
perf
doesn't reveal any more low-hanging fruit.