ipython/ipython — pull request #2868 by takluyver (2013-01-31 14:13:36+00:00)
Title: Import performance

Defer various imports for a small reduction in startup time.

**Question**: `IPython.lib.__init__` previously loaded `IPython.lib.inputhook` to export some of its functions. This meant that importing anything from `IPython.lib` also loaded inputhook. For now, I've just removed that import, but that is an API change, because the functions are no longer accessible as e.g. `IPython.lib.enable_qt4`. Do we want to export some or all of them as lazy-loading wrappers?

Timing command, borrowed [from Openoffice](http://wiki.openoffice.org/wiki/Cold-start-simulator#Linux_.2F_Cold_start_simulator) to simulate cold start:

`$ sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches; time ipython3 -c pass`

Results with this branch: 7.68, 7.64, 7.35, 7.38 s 'real'
Results with master: 8.17, 8.04, 7.81, 7.77

Admittedly not a big improvement, but it's a step in the right direction.

The number of imports (including re-imports) pulled in by `IPython.core.interactiveshell` drops from 1318 to 1057, while `len(sys.modules)` after starting plain IPython drops from 324 to 277.