Dear @LeWhoo ,
Here is a first attempt to reproduce your issue, which so far has not happened. I think you may be finding yourself in a situation where you are reading inefficiently and seeing some cumulated effects of that. I have created this github repository GitHub - vepadulano/root-forum-64767 · GitHub
In the repo you will find some preparatory code to generate the dictionary for ROOT::RVec<std::vector<std::vector<foat>>>, together with a Python script. In the script, I keep track of the RSS used during the for loop with the Range + AsNumpy calls.
Keeping a similar approach as your initial post, shows some fluctuation in terms of RSS in-between different iterations (albeit still fairly small). But when I move to a for loop that takes into account cluster boundaries, then I see practically no fluctuation in-between iterations. I do see something in the neighbourhood of 0.5MB, but I don’t think this can be called a leak at this stage.
For a brief explanation of what a “cluster” is, this is the smallest compressed group of entries of a TTree on disk. This means that when you read back the TTree from disk, you will be uncompressing an entire cluster of entries at a time, irrespective of how many entries you need to read. For example, all the files you sent me each have 1 cluster. That means that when reading each tree of the chain, the entire tree will be read in memory, even if you just request a smaller number of entries via Range. Even more concretely, the first file has 197 entries and only one cluster [0, 197). When you call Range(0, 100), the TTree will still uncompress from disk all 197 entries. This is the same in C++, Python, with or without RDataFrame, with or without ROOT I/O (i.e. any software reading TTree will do this).
Can I ask you to take a look at my example, maybe try to run it and reproduce it, and in case tell me what I am missing to show the leak you see?
On my machine, I get the following:
Delta RSS before for loop: 434.71
begin=0,end=197
pmem(rss=615362560, vms=3308306432, shared=334733312, text=4096, lib=0, data=2581798912, dirty=0)
Delta RSS: 145.05
begin=197,end=483
pmem(rss=615882752, vms=3308609536, shared=334733312, text=4096, lib=0, data=2582093824, dirty=0)
Delta RSS: 0.52
begin=483,end=578
pmem(rss=616181760, vms=3308765184, shared=334733312, text=4096, lib=0, data=2582249472, dirty=0)
Delta RSS: 0.30
begin=578,end=677
pmem(rss=616595456, vms=3308765184, shared=334733312, text=4096, lib=0, data=2582249472, dirty=0)
Delta RSS: 0.41
begin=677,end=781
pmem(rss=617107456, vms=3309228032, shared=334733312, text=4096, lib=0, data=2582712320, dirty=0)
Delta RSS: 0.51
Delta RSS w.r.t. before the for loop: 146.79
Note that the first iteration of the for loop shows an increase in memory usage but without further knowledge that’s most probably just due to the JITting of the column types and function instantiations for the first AsNumpy call.
Cheers,
Vincenzo