# RAM blows up while using Dataframes/Snapshot

**URL:** <https://root-forum.cern.ch/t/ram-blows-up-while-using-dataframes-snapshot/54070>\
**Category:** ROOT\
**Tags:** rdataframe\
**Created:** [March 16, 2023, 3:05pm UTC](https://root-forum.cern.ch/t/ram-blows-up-while-using-dataframes-snapshot/54070 "2023-03-16T15:05:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShaliniEpari](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@ShaliniEpari](https://root-forum.cern.ch/u/ShaliniEpari)\
**Post date:** [March 16, 2023, 3:05pm UTC](https://root-forum.cern.ch/t/ram-blows-up-while-using-dataframes-snapshot/54070/1 "2023-03-16T15:05:54Z")

</div>

Hi,

I’m using  
----- ROOT Version: 6.26/06  
----- Python 3.8.13

I’m trying to merge two ROOT files with different branches (but same number of entries) in pyroot using AddFriend/dataframes/Snapshot. The file sizes are 50 MB and 200 kb. I’m using the following code:  
f1 = ROOT.TFile.Open(“file\_1.root”,“READ”) #50 MB  
f2 = ROOT.TFile.Open(“file\_2.root”,“READ”) #200 kB  
t1=f1.Get(“nominal”)  
t2=f2.Get(“nominal”)  
t1.AddFriend(t2)  
df = RDataFrame(t1)  
df.Snapshot(“nominal”,“new\_file.root”) #produces a file of size ~50MB, branches added etc, all good  
f2.Close()  
f1.Close()

The code works as expected, but uses ~1.2 GB RAM, which is crazy! I mapped the RAM usage, in the first 0.5 seconds, everything up to the RDataframe creation is executed. The df.Snapshot takes ~100 second, and that’s the part where the memory blows

 ![single](https://root-forum.cern.ch/uploads/default/original/3X/8/9/89ae4139bc5e8ff82c4191d856960d7fe92b543a.png)

Any pointers on why this might be happening? Or a better workaround 🙂  
While this is a test file, I’m dealing with files upto ~15 GB in size and such a blowup in RAM is not affordable with the system I use.

Cheers and thanks in advance!

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [March 16, 2023, 6:00pm UTC](https://root-forum.cern.ch/t/ram-blows-up-while-using-dataframes-snapshot/54070/2 "2023-03-16T18:00:31Z")

</div>

Hello @ShaliniEpari ,

and welcome to the ROOT forum!

If I understand correctly the assumption behind the question is that larger files will cause memory to grow even more, but that’s not usually the case – it could be that it will stay around that level, ROOT and RDataFrame generally try not to cache anything in memory that scales with the number of entries (there are exceptions but I don’t think they apply here).

As a first step I would suggest to switch to a more recent ROOT version, possibly v6.28, and see whether the situation is better there.

If that’s not the case, and 1.2 GB of resident memory is a deal breaker for your use case, we need to check where the allocations come from. You should run the program under `valgrind --tool=massif` and then post here the output of `ms_print` (see for example the instructions at [5.3.3.&nbsp;Profiling Heap and Stack Space with Massif Red Hat Enterprise Linux 6 | Red Hat Customer Portal](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/performance_tuning_guide/ch05s03s03); the discussion at [Optimize memory usage while using RDataFrame - #3 by eguiraud](https://root-forum.cern.ch/t/optimize-memory-usage-while-using-rdataframe/54014/3) might also interest you).

All the best,  
Enrico

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [March 30, 2023, 6:01pm UTC](https://root-forum.cern.ch/t/ram-blows-up-while-using-dataframes-snapshot/54070/3 "2023-03-30T18:01:06Z")

</div>

Closed on March 30, 2023, 6:01pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
