3 ms·
Yeah this is one of my longstanding annoyances with Python... the interpreter is quite slow to start up because every import generates a ton of stat() calls. M
by chubot 12y ago
Yeah this is one of my longstanding annoyances with Python... the interpreter is quite slow to start up because every import generates a ton of stat() calls. Moreover, there is a tendency to use a very long PYTHONPATH, which increases the number of stats.
It's basically doing random access I/O (the slowest thing your computer can do) proportional to (large constant factor) * (num imports in program) * (length of PYTHONPATH).
When you can use it, a shebang of
#!/usr/bin/python -S
can speed things up substantially.
Perl starts up an order of magnitude faster too (more like 3ms than 30ms). Ruby seems to have the same problem as Python.
- im3w1l 12y agoHmm should be possible to reduce that to num imports + length of pythonpath, no?
- sp332 12y agoFor each import statement, it has to check each directory in the path. So (num imports) * (length of path).
- pekk 12y agoWhat are you doing that you are noticing this routinely and finding it to be a large annoyance?
- price 12y agoAny command-line script in Python that uses a significant codebase or a significant number of libraries. For me the main example is Mercurial -- it takes about 200ms (on my Mac) to run even a trivial command, and that's plenty long enough to get in the way. It's about 60ms on my other laptop (Linux), and that's just at the threshold of noticeable and annoying.