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).
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)
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.