`TChain::GetEntries` internal caching ineffective?
メンテナーはふだん 1 日以内に返信
@pcanal がすでに取り組んでいます。
2026年10月16日 から。
評価
この issue はまだ評価されていません。
説明
Check duplicate issues.
- Checked for duplicates
Description
We experienced some longer-than-expected delays when using Podio (internally using a TChain) when switching between the files of a chain. Claude traced this to our, maybe too paranoid, check in the event loop to see if the current entry is in the range of the chain before we access it, e.g. something like:
for (Long64_t i = 0; i < nEntries; ++i)
if (i < ch.GetEntries())
ch.GetEntry(i);
which causes us to spend up to 50% of the total runtime in TChain::GetEntries for essentially empty event loops.
Indeed, it looks like the internal caching machinery for fEntries in GetEntries is reset by TChain::LoadTree (called by GetEntry) here:
https://github.com/root-project/root/blob/fbcf83fe9a58e65f36ba55bdc3821a7983f4799a/tree/tree/src/TChain.cxx#L1559
This is causing the event loop to open many more files than expected, which can be seen when running the reproducer below as root -q repro_chain_getentries.C, yielding
Processing repro_chain_getentries.C...
files in chain: 10 files opened in loop: 55
files in chain: 100 files opened in loop: 5050
files in chain: 1000 files opened in loop: 500500
This becomes especially painful when the files are on EOS...
Reproducer
#include <TChain.h>
#include <TFile.h>
#include <TTree.h>
#include <iostream>
void repro_chain_getentries()
{
{
TFile file("chain_ge.root", "RECREATE");
TTree t("t", "t");
t.Fill();
t.Write();
}
for (int nFiles : {10, 100, 1000}) {
TChain ch("t");
for (int f = 0; f < nFiles; ++f)
ch.Add("chain_ge.root");
const auto nEntries = ch.GetEntries();
const auto opensBefore = TFile::GetFileCounter();
for (Long64_t i = 0; i < nEntries; ++i)
// Some (paranoid?) bounds check
if (i < ch.GetEntries())
ch.GetEntry(i);
std::cout << "files in chain: " << nFiles
<< " files opened in loop: " << TFile::GetFileCounter() - opensBefore << '\n';
}
}
ROOT version
------------------------------------------------------------------
| Welcome to ROOT 6.40.04 https://root.cern |
| (c) 1995-2025, The ROOT Team; conception: R. Brun, F. Rademakers |
| Built for linuxx8664gcc on Oct 07 2026, 01:16:29 |
| From tags/6-40-04@6-40-04 |
| With g++ (GCC) 16.1.0 std202302 |
| Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q' |
------------------------------------------------------------------
Installation method
source /cvmfs/sw-nightlies.hsf.org/key4hep/setup.sh
Operating system
Alma9
Additional context
No response
- 主要言語
- C++
- スター
- 3.3k
- フォーク
- 1.6k
- 平均マージ
- 2日 16時間
- マージ済み PR(30日)
- 194
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
root-project/root のほかの issue
-
thisroot.sh: wrong ROOTSYS in zsh when the shell's command line has a newline対応中かも @dpiparo が 2 日前に担当しました。 オープンbug in:Build System
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
root-project/root#23746 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
[tmva][sofie] Inputs of unsupported type (e.g. float16) give code that does not compile instead of an error対応中かも @lmoneta が 12 日前に担当しました。 オープンAI-Assisted bug in:SOFIE
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
root-project/root#23655 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 71/100
root-project/root#23790 ·
メンテナーはふだん 1 日以内に返信
-
bug in:Core Libraries
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
root-project/root#23777 ·
メンテナーはふだん 1 日以内に返信
-
[PyROOT] Segfault at exit deleting a branch with a Cling-generated collection destructor after cppyy instantiated a template対応中かも @guitargeek が 5 日前に担当しました。 オープンbug in:Python Interface
難易度 5/5 1週間以上 初心者へのやさしさ 12/100
root-project/root#23728 · コメント 8 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
root-project/root の issue をすべて見る
似ている issue
-
[Docs] CONTRIBUTING still says FreeType 2.14.3 and TabLabel.h says ImGui 1.92.9b after the bumps対応中かも @mgradwohl が今日担当しました。 オープンagent:WSL documentation LOW
難易度 1/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
finalburnneo/FBNeo#2820 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
area/ysql kind/enhancement priority/medium status/awaiting-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
yugabyte/yugabyte-db#35578 ·
メンテナーはふだん 1 日以内に返信
-
cudf-polars feature request
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
メンテナーはふだん 2 日以内に返信
-
(S1 - Need confirmation)
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
CleverRaven/Cataclysm-DDA#89212 ·
メンテナーはふだん 1 日以内に返信