# RDataFRame: Should I use Cache() when creating multiple Histo3D plots over the same RDF

**URL:** <https://root-forum.cern.ch/t/rdataframe-should-i-use-cache-when-creating-multiple-histo3d-plots-over-the-same-rdf/63942>\
**Category:** ROOT\
**Tags:** python, rdataframe\
**Created:** [July 28, 2025, 4:21pm UTC](https://root-forum.cern.ch/t/rdataframe-should-i-use-cache-when-creating-multiple-histo3d-plots-over-the-same-rdf/63942 "2025-07-28T16:21:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![attikis](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/attikis/32/23607_2.png) [@attikis](https://root-forum.cern.ch/u/attikis)\
**Post date:** [July 28, 2025, 4:21pm UTC](https://root-forum.cern.ch/t/rdataframe-should-i-use-cache-when-creating-multiple-histo3d-plots-over-the-same-rdf/63942/1 "2025-07-28T16:21:16Z")

</div>

Hi ROOT experts,

I’m working on a multi-threaded analysis pipeline using RDataFrame (RDF), and I’d like your advice regarding the possible performance benefits of using .Cache() in our setup.

Here’s what I’m doing:  
• We define a number of variables and loop over them.  
• For each variable, we define a derived column using a multiplexer function.  
• Then we create 3D histograms (using Histo3D) for each variable, with axes: variable, dataset index, and filter index.  
• We do this for a single rdf but with optionally the creation of multiple other rdf instances in the future (for different purposes).

This means I loop over all variables, define a derived column per variable (once), and create multiple histograms over the same rdf.

Would using .Cache() after the .Define(…) step be beneficial in this case? Specifically, would it improve performance (e.g., avoiding re-evaluating the multiplexer(…) function for each histogram)? Or does RDF already optimize this internally when only one Define and one Histo3D is made per variable?

Also, would .Cache() be more appropriate at the full dataframe level (rdf.Cache()) before the loop, or per derived variable?

Thanks in advance for your insights!

Best regards,  
Alexandros

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [July 28, 2025, 7:09pm UTC](https://root-forum.cern.ch/t/rdataframe-should-i-use-cache-when-creating-multiple-histo3d-plots-over-the-same-rdf/63942/2 "2025-07-28T19:09:47Z")

</div>

I think @vpadulan can help here

---

<div class="post-metadata">

**Author:** ![attikis](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/attikis/32/23607_2.png) [@attikis](https://root-forum.cern.ch/u/attikis)\
**Post date:** [July 31, 2025, 8:42am UTC](https://root-forum.cern.ch/t/rdataframe-should-i-use-cache-when-creating-multiple-histo3d-plots-over-the-same-rdf/63942/3 "2025-07-31T08:42:25Z")

</div>

Hi all,

any feedback on this? That would be greatly appreciated.

Cheers,  
Alexandros

---

<div class="post-metadata">

**Author:** ![attikis](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/attikis/32/23607_2.png) [@attikis](https://root-forum.cern.ch/u/attikis)\
**Post date:** [August 11, 2025, 8:56am UTC](https://root-forum.cern.ch/t/rdataframe-should-i-use-cache-when-creating-multiple-histo3d-plots-over-the-same-rdf/63942/4 "2025-08-11T08:56:55Z")

</div>

Hi all,

any feedback would be greatly appreciated. Perhaps @vpadulan as already suggested?

Cheers,  
Alexandros

---

<div class="post-metadata">

**Author:** ![silverweed](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/silverweed/32/36670_2.png) [@silverweed](https://root-forum.cern.ch/u/silverweed)\
**Post date:** [August 21, 2025, 9:26am UTC](https://root-forum.cern.ch/t/rdataframe-should-i-use-cache-when-creating-multiple-histo3d-plots-over-the-same-rdf/63942/5 "2025-08-21T09:26:39Z")

</div>

Hello @attikis,

I’m not a RDF expert, but judging from the documentation and from what you said, specifically:

> Or does RDF already optimize this internally when only one Define and **one Histo3D is made per variable**?

it would seem to me that Cache() would not help you here. The RDF doc says:

> Use `Cache` if you know you will only need a subset of the (`Filter`ed) data that fits in memory and that will be accessed many times.

so if you are only creating one Histo per variable I would not expect the data to be accessed many times, therefore Cache would only make things slower by making an additional copy of the data. However, as is always the case with performance optimization, the only way to know for sure is to measure, so I would try doing that if you’re unsure.

---

<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:** [September 4, 2025, 9:26am UTC](https://root-forum.cern.ch/t/rdataframe-should-i-use-cache-when-creating-multiple-histo3d-plots-over-the-same-rdf/63942/6 "2025-09-04T09:26:45Z")

</div>

Closed on September 4, 2025, 9:26am UTC

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