My understanding is that imports can be slow when you import the first time, and then they should be cached for subsequent imports. However that's not what I'm experiencing. And I really don't think I'm doing something wrong like having the wrong settings because I remember this same thing happening when I tried using Python a year ago. I'm doing the following:
from langchain_google_genai import ChatGoogleGenerativeAI
from browser_use import Agent
Each of those import statements take about 6 seconds each. This means each time I start my program I have to wait at least 10 seconds. Is that normal? I've heard the benefit of using Python in machine learning and AI contexts was the faster iteration time because you didn't have to recompile as you do in C++. Also, I've used NodeJS, and I don't remember the imports ever taking long, though to be fair I didn't have large projects. Is this normal?
Also, I stepped through the code to check whether it was doing io like reading in a file, as this is slow no matter what language you use, including C++, but no, it just seems slow overall.
Here is a minimal example of what's happening.
My understanding is that imports can be slow when you import the first time, and then they should be cached for subsequent imports. However that's not what I'm experiencing. And I really don't think I'm doing something wrong like having the wrong settings because I remember this same thing happening when I tried using Python a year ago. I'm doing the following:
from langchain_google_genai import ChatGoogleGenerativeAI
from browser_use import Agent
Each of those import statements take about 6 seconds each. This means each time I start my program I have to wait at least 10 seconds. Is that normal? I've heard the benefit of using Python in machine learning and AI contexts was the faster iteration time because you didn't have to recompile as you do in C++. Also, I've used NodeJS, and I don't remember the imports ever taking long, though to be fair I didn't have large projects. Is this normal?
Also, I stepped through the code to check whether it was doing io like reading in a file, as this is slow no matter what language you use, including C++, but no, it just seems slow overall.
Here is a minimal example of what's happening.
Share Improve this question edited Mar 24 at 3:21 Zebrafish asked Mar 21 at 21:44 ZebrafishZebrafish 15k3 gold badges66 silver badges153 bronze badges 18 | Show 13 more comments1 Answer
Reset to default 0here's what i see
( h/ware/OS: Intel(R) Core(TM) i5-10310U CPU @ 1.70GHz hp laptop running WSL )
cat /tmp/z.py
import time
start = time.time()
print( "RUNNING : from langchain_google_genai import ChatGoogleGenerativeAI")
from langchain_google_genai import ChatGoogleGenerativeAI
end = time.time()
print(f"import took {end-start} seconds\n")
t1=end-start
start = time.time()
print( "RUNNING : from browser_use import Agent")
from browser_use import Agent
end = time.time()
print(f"import took {end-start} seconds\n")
t2=end-start
print(f"total time taken: {t1+t2}")
#
# first run
#
python3 /tmp/z.py
RUNNING : from langchain_google_genai import ChatGoogleGenerativeAI
import took 1.6047194004058838 seconds
RUNNING : from browser_use import Agent
INFO [browser_use] BrowserUse logging setup complete with level info
INFO [root] Anonymized telemetry enabled. See https://docs.browser-use/development/telemetry for more information.
import took 0.9617722034454346 seconds
total time taken: 2.5664916038513184
#
# a second time
#
python3 /tmp/z.py
RUNNING : from langchain_google_genai import ChatGoogleGenerativeAI
import took 0.9231696128845215 seconds
RUNNING : from browser_use import Agent
INFO [browser_use] BrowserUse logging setup complete with level info
INFO [root] Anonymized telemetry enabled. See https://docs.browser-use/development/telemetry for more information.
import took 0.5260987281799316 seconds
total time taken: 1.4492683410644531
#
# summary ....
#
grep 'total' /tmp/z.log | awk '{ total+=$NF } END { print "AVE time: " total/FNR " over " FNR " iterations"}'
AVE time: 1.37213 over 76 iterations
prints
after each to see which is the holdup. Your simple module should import instantly, but the other two may take a bit if they have initialization like I mentioned. I poked through the code for each and couldn't find any such blocking code, but I only looked briefly. If even your simple module takes forever to import, that is not typical. – Carcigenicate Commented Mar 21 at 22:00fs.readFileSync
at the module level. – Carcigenicate Commented Mar 21 at 22:36