Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Python is slow – it doesn't have to be (kodare.net)
1 point by boxed on May 19, 2020 | hide | past | favorite | 2 comments


    import numpy
I actively avoid using numpy for anything but long-running jobs, because of its incredibly slow startup time.

As I recall, "import numpy" loads all of its submodules, so that people can do:

    import numpy
    numpy.subA.subB.subC.funcD()
instead of the "normal" way:

    from numpy.subA.subB import subC
    subC.funcD()
In my test now, using "python -v -c 'import numpy'". it imported the following 94 modules or submodules:

     numpy._globals, numpy.__config__, numpy.version, numpy._distributor_init,
     numpy.core._multiarray_umath, numpy.compat._inspect numpy.compat.py3k,
     numpy.compat, numpy.core.overrides, numpy.core.multiarray,
     numpy.core.umath, numpy.core._string_helpers, numpy.core._dtype,
     numpy.core._type_aliases, numpy.core.numerictypes, numpy.core._asarray,
     numpy.core._exceptions, numpy.core._methods, numpy.core.fromnumeric,
     numpy.core.shape_base, numpy.core._ufunc_config, numpy.core.arrayprint,
     numpy.core.numeric, numpy.core.defchararray, numpy.core.records,
     numpy.core.memmap, numpy.core.function_base, numpy.core.machar,
     numpy.core.getlimits, numpy.core.einsumfunc,
     numpy.core._multiarray_tests, numpy.core._add_newdocs,
     numpy.core._dtype_ctypes, numpy.core._internal, numpy._pytesttester,
     numpy.core, numpy.lib.mixins, numpy.lib.ufunclike, numpy.lib.type_check,
     numpy.lib.scimath, numpy.lib.twodim_base, numpy.linalg.lapack_lite,
     numpy.linalg._umath_linalg, numpy.linalg.linalg, numpy.linalg,
     numpy.matrixlib.defmatrix, numpy.matrixlib, numpy.lib.histograms,
     numpy.lib.function_base, numpy.lib.stride_tricks, numpy.lib.index_tricks,
     numpy.lib.nanfunctions, numpy.lib.shape_base, numpy.lib.polynomial,
     numpy.lib.utils, numpy.lib.arraysetops, numpy.lib.format,
     numpy.lib._datasource, numpy.lib._iotools, numpy.lib.npyio,
     numpy.lib.financial, numpy.lib.arrayterator, numpy.lib.arraypad,
     numpy.lib._version, numpy.lib, numpy.fft._pocketfft_internal,
     numpy.fft._pocketfft, numpy.fft.helper, numpy.fft,
     numpy.polynomial.polyutils, numpy.polynomial._polybase,
     numpy.polynomial.polynomial, numpy.polynomial.chebyshev,
     numpy.polynomial.legendre, numpy.polynomial.hermite,
     numpy.polynomial.hermite_e, numpy.polynomial.laguerre, numpy.polynomial,
     numpy.random._common, numpy.random._bit_generator,
     numpy.random._bounded_integers, numpy.random._mt19937,
     numpy.random.mtrand, numpy.random._philox, numpy.random._pcg64,
     numpy.random._sfc64, numpy.random._generator, numpy.random._pickle,
     numpy.random, numpy.ctypeslib, numpy.ma.core, numpy.ma.extras, numpy.ma,
     numpy


It used to be much worse as I remember too. And numpy isn't even worst. Not by a long shot. On my machine importing numpy is ~0.2s, while requests is ~0.3. This seems pretty crazy considering how huge numpy is an how tiny requests is!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: