`TChain::GetEntries` internal caching ineffective?
Maintainer thường phản hồi trong vòng 1 ngày
@pcanal đang làm issue này rồi.
Từ ngày 16/10/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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
- Ngôn ngữ chính
- C++
- Star
- 3.3k
- Fork
- 1.6k
- Merge trung bình
- 2 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 188
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của root-project/root
-
thisroot.sh: wrong ROOTSYS in zsh when the shell's command line has a newlineCó thể đã có người làm @dpiparo đã nhận 4 ngày trước. Đang mởbug in:Build System
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
root-project/root#23746 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[tmva][sofie] Inputs of unsupported type (e.g. float16) give code that does not compile instead of an errorCó thể đã có người làm @lmoneta đã nhận 14 ngày trước. Đang mởAI-Assisted bug in:SOFIE
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
root-project/root#23655 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[RDataFrame] Code that transforms `#var` alias to `R_rdf_sizeof_var` does not respect string literalsCó thể đã có người làm @vepadulano đã nhận 1 ngày trước. Đang mởbug in:RDataFrame
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 71/100
root-project/root#23790 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
TDataMember::GetOffset interfers to TDataMember::GetOffsetCintCó thể đã có người làm @pcanal đã nhận 1 ngày trước. Đang mởbug in:Core Libraries
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
root-project/root#23777 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[PyROOT] Segfault at exit deleting a branch with a Cling-generated collection destructor after cppyy instantiated a templateCó thể đã có người làm @guitargeek đã nhận 7 ngày trước. Đang mởbug in:Python Interface test wit cppjit
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 12/100
root-project/root#23728 · 9 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của root-project/root
Issue tương tự
-
[mimalloc] update to 3.6.0Đang mởcategory:port-update
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 2 ngày
-
MinGW build faillureĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
facebookresearch/faiss#5775 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Eval bug: minimax-m3: build_moe_ffn() drops the per-expert NVFP4 scale → garbled output (M3.1 Flash)Đang mởbug-unconfirmed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
secondlife/viewer#6507 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
clang:frontend code-cleanup HLSL
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
llvm/llvm-project#235100 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày