-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fixing an O(N^2) scaling problem caused by TTree::Draw() #650
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
Conversation
Can one of the admins verify this patch? |
@pcanal : This is roughly what we discussed. Can you please take a look? |
build please |
@phsft-bot build, please |
tree/treeplayer/src/TTreeFormula.cxx
Outdated
// caches to keep track of where we are across function invocations | ||
// will avoid an O(N^2) scaling | ||
// reset them if instance=0 is seen | ||
static Int_t local_index_cache = 0; |
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 need to be thread_local :)
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.
Yes of course. Let us focus on the correctness for one thread for the moment. The question is then if we want to use static stuff for the cache or a member variable of the TTreeFormula. The latter would not have a penalty to access (probably).
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.
actually I am very wrong :( ...
Those actually need to be data member. More than once TTreeFormula can be handled/processed during the same operation and they can also be nested. For example
tree->Draw("px:pz:fTrack[index]");
the call to EvalInstance for each i will be interleaved and the one with the index will be nested.
Starting build on |
Build failed on ubuntu14/native. Warnings:
Failing tests: |
Build failed on slc6/gcc49. Warnings:
Failing tests:
|
Build failed on slc6/gcc62. Warnings:
Failing tests:
|
tree/treeplayer/src/TTreeFormula.cxx
Outdated
// reset them if instance=0 is seen | ||
static Int_t local_index_cache = 0; | ||
static Int_t virt_accum_cache = 0; | ||
if (instance==0) { |
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.
It might be more stable to have here
if (instance < instance_cache)
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.
Implemented caching using data members + did some cleanup.
tree/treeplayer/src/TTreeFormula.cxx
Outdated
// caches to keep track of where we are across function invocations | ||
// will avoid an O(N^2) scaling | ||
// reset them if instance=0 is seen | ||
static Int_t local_index_cache = 0; |
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.
actually I am very wrong :( ...
Those actually need to be data member. More than once TTreeFormula can be handled/processed during the same operation and they can also be nested. For example
tree->Draw("px:pz:fTrack[index]");
the call to EvalInstance for each i will be interleaved and the one with the index will be nested.
Build failed on mac1012/native. Warnings:
Failing tests: |
c470183
to
1e67dea
Compare
1e67dea
to
229c886
Compare
I will be able to do some formatting. git-clang-format causes some global change however. |
tree/treeplayer/inc/TTreeFormula.h
Outdated
@@ -200,7 +210,7 @@ friend class TTreeFormulaManager; | |||
virtual TTree* GetTree() const {return fTree;} | |||
virtual void UpdateFormulaLeaves(); | |||
|
|||
ClassDef(TTreeFormula, 10); //The Tree formula | |||
ClassDef(TTreeFormula, 11); // The Tree formula |
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.
No need to increment. The onfile format did not change.
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.
ok
491bd41
to
0531abb
Compare
@phsft-bot build |
Starting build on |
Build failed on slc6/gcc62. Warnings:
Failing tests: |
Build failed on ubuntu14/native. Warnings:
Failing tests: |
Build failed on mac1012/native. Warnings:
Failing tests: |
Build failed on slc6/gcc49. Warnings:
Failing tests: |
Build failed on centos7/gcc49. Warnings:
Failing tests: |
0531abb
to
a2b3866
Compare
* TTreeFormala::GetRealInstance repeatedly went trough a while loop that was trasversed again and again for each new query (with lineary increasing instances). This led to a real problem when drawing on a branch that consistent of many data objects (themselves containing small variable sized containers). * The problem is fixed by caching the state of a previous call.
a2b3866
to
c172e22
Compare
@phsft-bot build, please |
Starting build on |
Build failed on centos7/gcc49. Warnings:
|
Hi @sawenzel, has this been merged in another PR? If not, could you please rebase and push so that we can test against the latest master? Most unrelated test failures from above have been fixed. Thanks! |
I think this has been merged can be closed. |
This is a first attempt at solving a scaling problem observed during TTree::Draw of a branch that contains a TClonesArray where each element contains another small vector container.
The fix works for me.