-
Notifications
You must be signed in to change notification settings - Fork 1.5k
TDirectory::GetObject is needlessly slow #8046
Description
Hello,
I was trying to improve the throughput of a program that deals with ROOT files containing gazillions of histograms. I ended up using linux perf, and found that the culprit is
TDirectoryFile::GetObjectChecked(const char *namecycle, const TClass* expectedClass)
A quick read through the code shows that the problem is that in the case of a histogram not yet read in memory, the iteration through the list of keys is linear !!! On the other hand the function
TKey *TDirectoryFile::GetKey(const char *name, Short_t cycle) const
is correctly implemented, i.e see
TIter next( ((THashList *)(GetListOfKeys()))->GetListForObject(name) );
to make use of the THashList capabilities of the list of keys.
I ended up cutting the running time of my program by a factor 4-5 by replacing
m_baseDir->GetObject(hname, res);
by
TKey* res_key = m_baseDir->GetKey(hname);
if(res_key) {
res = (TH1*)(res_key->ReadObj());
}
Would be nicer to fix TDirectoryFile::GetObjectChecked directly, as well as TDirectoryFile::Get.