increased load time importing from panda3d.core

Seems there is some significant cost for using panda3d.core instead of pandac.PandaModules.
Subsequent imports should be close to free, but I discovered that using the new import method was adding a lot of time to load up my game.
I usually import * at the top of my py files that need to use Panda classes, in total I had 32 files with import *, so it was adding a good 10 seconds or more to the load time.

import time

start = time.time()
for i in range(0, 100):
    from pandac.PandaModules import *
print 'import time', time.time() - start

start = time.time()
for i in range(0, 100):
    from panda3d.core import *
print 'import time', time.time() - start
import time 0.018000125885
import time 42.260999918

Huh, I have no idea why that would be. It’s supposed to be much faster, due to the way it works.

I comfirm having the same on my machine.
0.04 seconds with the old way, 61 seconds with the new.

Python usually doesn’t import something which was already imported. Perhaps the new method confuses Python somehow?

Which platforms do you guys use? I certainly never get a 60-second delay when I’m starting my Python scripts.

Windows 7 64bit.

he is importing it 100 times to make it more noticeable.

Win XP, buildbot version 2-3 weeks old, ancient hardware.

from pandac.PandaModules import * load in ~1 (0.98)second no matter how many times

from panda3d.core import * loads in ~1 (1.06)second every call, so with 10 loops it loads in 10 sec, with 100 in 100 seconds.

Found the problem. It was just a matter of making cache the results of each call to getattr(), so that subsequent calls to retrieve the same symbol in the future don’t have to revisit the same codepath. Fix committed.


Oh wow, thanks David!

Weird the issue was noticed only now. The new importing method has been around for a year, if not more.

I knew accessing things as:
was very slow, so I had to use from imports. I’m guessing this fix will fix that as well. Excellent.