`TChain::GetEntries` internal caching ineffective?
I maintainer di solito rispondono entro 1 giorno
@pcanal ci sta già lavorando.
Dal 16/10/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
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
- Lingua principale
- C++
- Stelle
- 3.3k
- Fork
- 1.6k
- Merge medio
- 2g 17h
- PR unite (30g)
- 188
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di root-project/root
-
thisroot.sh: wrong ROOTSYS in zsh when the shell's command line has a newlineForse già presa @dpiparo l’ha presa 3 giorni fa. Apertabug in:Build System
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
root-project/root#23746 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[tmva][sofie] Inputs of unsupported type (e.g. float16) give code that does not compile instead of an errorForse già presa @lmoneta l’ha presa 13 giorni fa. ApertaAI-Assisted bug in:SOFIE
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
root-project/root#23655 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[RDataFrame] Code that transforms `#var` alias to `R_rdf_sizeof_var` does not respect string literalsForse già presa @vepadulano l’ha presa oggi. Apertabug in:RDataFrame
Difficoltà 3/5 1-2 giorni Idoneità per principianti 71/100
root-project/root#23790 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
TDataMember::GetOffset interfers to TDataMember::GetOffsetCintForse già presa @pcanal l’ha presa oggi. Apertabug in:Core Libraries
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
root-project/root#23777 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[PyROOT] Segfault at exit deleting a branch with a Cling-generated collection destructor after cppyy instantiated a templateForse già presa @guitargeek l’ha presa 6 giorni fa. Apertabug in:Python Interface test wit cppjit
Difficoltà 5/5 Più di una settimana Idoneità per principianti 12/100
root-project/root#23728 · 9 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di root-project/root
Issue simili
-
bug topic:shaders
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
godotengine/godot#124800 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
swiftlang/indexstore-db#306 ·
-
Python PointcloudAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
ArduCAM/Arducam_tof_camera#125 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 87/100
maplibre/maplibre-native#4822 ·
I maintainer di solito rispondono entro 1 giorno
-
bug-unconfirmed
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno