`import ROOT` is slow


Just to add a comment here since I’m facing a similar issue. My code is rather simple and runs in 0.261s, but if I add:

from ROOT import TFile

and even not loading any file, it slows down to run in 7.4 seconds.

I’m not sure this is related to my personal installation or other interface between ROOT and python.

Homebrew 3.2.10-25-g2cc3d3e
ROOT 6.22/08
Python 3.9.6

you should check how long it takes to only run from ROOT import TFile and/or whether the runtime of the rest of the code is affected by the addition of the import, you might just be measuring a slow import ROOT for whatever reason, e.g. network filesystem latency or a very long PYTHONPATH where only the last entry is the good one (just making stuff up – but I think it’s two different problems: slow dispatching when you call something like ROOT.Math.root_sqrt vs slow import ROOT).

Dear Enrico,

Maybe the two problems are not really related. Indeed, I did a simple check like:

#!/usr/bin/env python3.9

from ROOT import TFile

print("hello world")

7 seconds against 0.1 seconds with/o ROOT. I’ll investigate my system a little more, but I don’t see any PYTHONPATH ambiguity that could explain the issue.

Importing ROOT takes a little time: on my system it’s ~1s with a local ROOT build and 0.6s/4s with conda (4 seconds if the files are not in the filesystem cache, i.e. only the first time I do it after turning on the laptop). Not great, but it’s a one-time cost and it won’t slow down the actual data processing or calculations.

(I moved this exchange to a new thread as it was about a different topic than the original thread. @etejedor might know why import ROOT takes so long on your system and/or if there is anything that can be done to speed it up)

Is it

from ROOT import TFile

which takes time or just import ROOT (or any other import like from ROOT import TTree)?

One time would be fine with me, but I see that happening every time I execute my test code.

Yes, it does happen with TTree, TH1, etc.

It seems to not be the PYTHONPATH. I ran the test code removing the paths one by one and I still get the same issue. Python verbose seems to not point any anomaly either.

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