Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve symengine import time #417

Merged
merged 3 commits into from
Sep 1, 2022

Conversation

eendebakpt
Copy link
Contributor

@eendebakpt eendebakpt commented Aug 26, 2022

During the symengine import the pytest package is imported which adds to the import duration. The pytest package is only required for the unit testing. This PR moves the pytest import to a seperate file.

Output of importtime-waterfall symengine
symengine (2072)
  symengine.lib.symengine_wrapper (6247)
    symengine.lib (878)
    collections.abc (525)
    backports_abc (1292)
    numbers (537)
    symengine.utilities (897)
      string (949)
        _string (42)
      py (1191)
        py._error (692)
        py._vendored_packages (635)
        py._vendored_packages.apipkg (1131)
          py._vendored_packages.apipkg.version (680)
        py._version (599)
      pytest (1029)
        _pytest (845)
          _pytest._version (686)
        _pytest._code (619)
          _pytest._code.code (7059)
            ast (1292)
              _ast (868)
            inspect (1717)
              dis (1208)
                opcode (522)
                  _opcode (40)
              linecache (438)
                tokenize (1043)
                  token (445)
            traceback (674)
            typing (2123)
            weakref (1103)
              _weakrefset (898)
            attr (1053)
              __future__ (973)
              attr.converters (810)
                attr._compat (644)
                  platform (2783)
                    subprocess (1152)
                      signal (1169)
                      threading (963)
                      fcntl (1364)
                      msvcrt (58)
                      _winapi (82)
                attr._make (2813)
                  copy (549)
                    org.python.core (20)
                      org.python (20)
                        org (1213)
                  attr._config (280)
                  attr.setters (293)
                    attr.exceptions (383)
              attr.filters (366)
              attr.validators (3959)
              attr._cmp (424)
              attr._funcs (320)
              attr._version_info (754)
              attr._next_gen (330)
            pluggy (752)
              pluggy._version (412)
              pluggy._manager (520)
                pluggy._tracing (303)
                pluggy._callers (285)
                  pluggy._result (461)
                pluggy._hooks (445)
                importlib.metadata (1440)
                  csv (600)
                    _csv (87)
                  email (518)
                  zipfile (1604)
                    binascii (74)
                    shutil (852)
                      zlib (66)
                      bz2 (633)
                        _compression (512)
                        _bz2 (915)
                      lzma (894)
                        _lzma (838)
                    struct (540)
                      _struct (74)
                  textwrap (1406)
                  importlib.metadata._adapters (568)
                    email.message (766)
                      uu (450)
                      quopri (442)
                      email.utils (616)
                        random (563)
                          math (63)
                          bisect (446)
                            _bisect (55)
                          _random (33)
                          _sha512 (36)
                        socket (1372)
                          _socket (1789)
                          selectors (869)
                            select (634)
                        datetime (1048)
                          _datetime (177)
                        email._parseaddr (370)
                          calendar (729)
                            locale (1150)
                        email.charset (396)
                          email.base64mime (289)
                            base64 (501)
                          email.quoprimime (410)
                          email.errors (857)
                          email.encoders (292)
                      email._policybase (432)
                        email.header (949)
                      email._encoded_words (427)
                      email.iterators (292)
                    importlib.metadata._text (365)
                      importlib.metadata._functools (302)
                  importlib.metadata._meta (464)
                  importlib.metadata._collections (410)
                  importlib.metadata._itertools (312)
                  importlib.abc (821)
            _pytest._code.source (1124)
            _pytest._io (610)
              _pytest._io.terminalwriter (774)
                _pytest._io.wcwidth (593)
                  unicodedata (839)
                _pytest.compat (1440)
                  py._path.local (1419)
                    py._path (569)
                    atexit (65)
                    uuid (829)
                      _uuid (715)
                    py._path.common (1161)
            _pytest._io.saferepr (857)
              pprint (602)
                dataclasses (846)
            _pytest.deprecated (632)
              _pytest.warning_types (1150)
            _pytest.pathlib (1087)
              _pytest.outcomes (749)
        _pytest.assertion (1187)
          _pytest.assertion.rewrite (2827)
            _pytest.assertion.util (1322)
              _pytest.config (2288)
                argparse (1026)
                  gettext (1230)
                shlex (547)
                _pytest.hookspec (1421)
                _pytest.config.exceptions (725)
                _pytest.config.findpaths (671)
                  iniconfig (868)
                _pytest.stash (686)
            _pytest.main (1530)
              _pytest.nodes (1246)
                _pytest.mark.structures (26)
                  _pytest.mark (1533)
                    _pytest.mark.expression (1803)
                    _pytest.mark.structures (2323)
                    _pytest.config.argparsing (1015)
              _pytest.fixtures (4043)
                _pytest.scope (750)
              _pytest.reports (1069)
              _pytest.runner (1762)
                bdb (797)
                _pytest.timing (673)
            atomicwrites (882)
              tempfile (646)
              fcntl (1334)
              ctypes (1270)
                _ctypes (3613)
                ctypes._endian (605)
          _pytest.assertion.truncate (599)
        _pytest.cacheprovider (1197)
          json (510)
            json.decoder (623)
              json.scanner (525)
                _json (52)
            json.encoder (565)
          _pytest.python (4074)
        _pytest.capture (1334)
        _pytest.debugging (921)
        _pytest.freeze_support (562)
        _pytest.legacypath (1176)
          _pytest.monkeypatch (861)
          _pytest.pytester (1799)
            gc (55)
            _pytest.tmpdir (1015)
          _pytest.terminal (1604)
        _pytest.logging (1252)
          logging (2000)
        _pytest.python_api (1145)
          decimal (433)
            _decimal (968)
        _pytest.recwarn (928)
    numpy (2141)
      numpy._globals (623)
      numpy.__config__ (345)
      numpy._distributor_init (278)
      numpy.core (814)
        numpy.version (281)
          numpy._version (249)
        numpy.core.multiarray (686)
          numpy.core.overrides (498)
            numpy.core._multiarray_umath (2904)
            numpy.compat._inspect (26)
              numpy.compat (443)
                numpy.compat._inspect (475)
                numpy.compat.py3k (348)
                  pickle5 (1240)
                  pickle (1474)
                    _compat_pickle (571)
                    _pickle (109)
                    org.python.core (20)
                      org.python (20)
                        org (1211)
        numpy.core.umath (359)
        numpy.core.numerictypes (468)
          numpy.core._string_helpers (305)
          numpy.core._type_aliases (466)
            numpy.core._dtype (311)
        numpy.core.numeric (788)
          numpy.core.shape_base (408)
            numpy.core.fromnumeric (609)
              numpy.core._methods (418)
                numpy.core._exceptions (455)
                numpy.core._ufunc_config (412)
                  contextvars (395)
                    _contextvars (50)
          numpy.core.arrayprint (660)
          numpy.core._asarray (329)
        numpy.core.defchararray (681)
        numpy.core.records (635)
        numpy.core.memmap (364)
        numpy.core.function_base (354)
        numpy.core._machar (310)
        numpy.core.getlimits (421)
        numpy.core.einsumfunc (403)
        numpy.core._add_newdocs (1269)
          numpy.core._multiarray_tests (773)
        numpy.core._add_newdocs_scalars (558)
        numpy.core._dtype_ctypes (458)
        numpy.core._internal (875)
        numpy._pytesttester (308)
      numpy.lib (874)
        numpy.lib.mixins (532)
        numpy.lib.scimath (374)
          numpy.lib.type_check (347)
            numpy.lib.ufunclike (361)
        numpy.lib.index_tricks (502)
          numpy.matrixlib (350)
            numpy.matrixlib.defmatrix (509)
              numpy.linalg (356)
                numpy.linalg.linalg (682)
                  numpy.lib.twodim_base (435)
                    numpy.lib.stride_tricks (341)
                  numpy.linalg._umath_linalg (739)
          numpy.lib.function_base (760)
            numpy.lib.histograms (418)
        numpy.lib.nanfunctions (451)
        numpy.lib.shape_base (381)
        numpy.lib.polynomial (1045)
        numpy.lib.utils (792)
        numpy.lib.arraysetops (709)
        numpy.lib.npyio (2646)
          numpy.lib.format (659)
          numpy.lib._datasource (1053)
          numpy.lib._iotools (668)
        numpy.lib.arrayterator (385)
        numpy.lib.arraypad (374)
        numpy.lib._version (318)
      numpy.fft (435)
        numpy.fft._pocketfft (604)
          numpy.fft._pocketfft_internal (758)
        numpy.fft.helper (355)
      numpy.polynomial (427)
        numpy.polynomial.polynomial (635)
          numpy.polynomial.polyutils (459)
          numpy.polynomial._polybase (506)
        numpy.polynomial.chebyshev (528)
        numpy.polynomial.legendre (541)
        numpy.polynomial.hermite (431)
        numpy.polynomial.hermite_e (424)
        numpy.polynomial.laguerre (418)
      numpy.random (419)
        numpy.random._pickle (528)
          numpy.random.mtrand (1537)
            numpy.random.bit_generator (985)
              numpy.random._common (1074)
                backports_abc (1214)
              secrets (435)
                hmac (521)
                  _hashlib (1111)
                  hashlib (765)
                    _blake2 (75)
            numpy.random._bounded_integers (1014)
            numpy.random._mt19937 (781)
          numpy.random._philox (719)
          numpy.random._pcg64 (847)
          numpy.random._sfc64 (781)
          numpy.random._generator (924)
      numpy.ctypeslib (596)
      numpy.ma (449)
        numpy.ma.core (2536)
        numpy.ma.extras (1184)
  symengine.functions (1180)
  symengine.printing (638)
This PR: output of importtime-waterfall symengine
symengine (309)
  symengine.lib.symengine_wrapper (4226)
    symengine.lib (144)
    collections.abc (180)
    backports_abc (161)
    numbers (355)
    symengine.utilities (342)
      re (538)
        enum (614)
        sre_compile (280)
          _sre (66)
          sre_parse (333)
            sre_constants (252)
        copyreg (150)
      string (649)
        _string (36)
    numpy (1977)
      numpy._globals (310)
      numpy.__config__ (173)
      numpy._distributor_init (109)
      numpy.core (840)
        numpy.version (142)
          __future__ (137)
          numpy._version (113)
            json (368)
              json.decoder (465)
                json.scanner (380)
                  _json (156)
              json.encoder (410)
        numpy.core.multiarray (586)
          numpy.core.overrides (258)
            numpy.core._multiarray_umath (2305)
              datetime (719)
                math (58)
                _datetime (151)
            numpy.compat._inspect (29)
              numpy.compat (248)
                numpy.compat._inspect (176)
                numpy.compat._pep440 (2067)
                numpy.compat.py3k (207)
                  pathlib (620)
                    fnmatch (142)
                    ntpath (251)
                      nt (129)
                      nt (120)
                      nt (124)
                      nt (115)
                    errno (66)
                    urllib.parse (859)
                      urllib (127)
                  pickle5 (138)
                  pickle (701)
                    struct (286)
                      _struct (70)
                    _compat_pickle (222)
                    _pickle (107)
                    org.python.core (14)
                      org.python (25)
                        org (126)
        numpy.core.umath (186)
        numpy.core.numerictypes (348)
          numpy.core._string_helpers (140)
          numpy.core._type_aliases (344)
            numpy.core._dtype (153)
        numpy.core.numeric (841)
          numpy.core.shape_base (294)
            numpy.core.fromnumeric (839)
              numpy.core._methods (219)
                numpy.core._exceptions (333)
          numpy.core._ufunc_config (190)
          numpy.core.arrayprint (496)
          numpy.core._asarray (153)
        numpy.core.defchararray (763)
        numpy.core.records (276)
        numpy.core.memmap (181)
        numpy.core.function_base (209)
        numpy.core._machar (250)
        numpy.core.getlimits (249)
        numpy.core.einsumfunc (237)
        numpy.core._add_newdocs (1083)
          numpy.core._multiarray_tests (253)
        numpy.core._add_newdocs_scalars (2235)
          platform (1721)
          subprocess (471)
            signal (737)
            threading (465)
              _weakrefset (771)
            msvcrt (152)
            _posixsubprocess (52)
            select (66)
            selectors (441)
        numpy.core._dtype_ctypes (204)
        numpy.core._internal (958)
          ast (377)
            _ast (810)
          ctypes (845)
            _ctypes (377)
            ctypes._endian (247)
        numpy._pytesttester (151)
      numpy.lib (363)
        numpy.lib.mixins (245)
        numpy.lib.scimath (281)
          numpy.lib.type_check (319)
            numpy.lib.ufunclike (246)
        numpy.lib.index_tricks (375)
          numpy.matrixlib (120)
            numpy.matrixlib.defmatrix (264)
              numpy.linalg (145)
                numpy.linalg.linalg (662)
                  numpy.lib.twodim_base (429)
                    numpy.lib.stride_tricks (281)
                  numpy.linalg._umath_linalg (307)
          numpy.lib.function_base (904)
            numpy.lib.histograms (245)
        numpy.lib.nanfunctions (387)
        numpy.lib.shape_base (411)
        numpy.lib.polynomial (503)
        numpy.lib.utils (588)
          textwrap (1131)
        numpy.lib.arraysetops (269)
        numpy.lib.npyio (502)
          weakref (424)
          numpy.lib.format (201)
          numpy.lib._datasource (219)
          numpy.lib._iotools (299)
        numpy.lib.arrayterator (159)
        numpy.lib.arraypad (224)
        numpy.lib._version (161)
      numpy.fft (198)
        numpy.fft._pocketfft (490)
          numpy.fft._pocketfft_internal (124)
        numpy.fft.helper (164)
      numpy.polynomial (265)
        numpy.polynomial.polynomial (351)
          numpy.polynomial.polyutils (187)
          numpy.polynomial._polybase (934)
        numpy.polynomial.chebyshev (291)
        numpy.polynomial.legendre (249)
        numpy.polynomial.hermite (248)
        numpy.polynomial.hermite_e (372)
        numpy.polynomial.laguerre (250)
      numpy.random (203)
        numpy.random._pickle (260)
          numpy.random.mtrand (1068)
            numpy.random.bit_generator (461)
              numpy.random._common (537)
                backports_abc (160)
              secrets (170)
                base64 (206)
                  binascii (79)
                hmac (325)
                  _hashlib (559)
                  hashlib (287)
                    _blake2 (61)
                    _sha3 (50)
                random (377)
                  bisect (144)
                    _bisect (34)
                  _sha512 (45)
                  _random (41)
            numpy.random._bounded_integers (213)
            numpy.random._mt19937 (167)
          numpy.random._philox (191)
          numpy.random._pcg64 (181)
          numpy.random._sfc64 (226)
          numpy.random._generator (501)
      numpy.ctypeslib (369)
      numpy.ma (256)
        numpy.ma.core (2471)
          inspect (1335)
            dis (398)
              opcode (250)
                _opcode (124)
            linecache (164)
              tokenize (860)
                token (156)
        numpy.ma.extras (913)
    atexit (42)
  symengine.functions (141)
  symengine.printing (136)

@bjodah
Copy link
Contributor

bjodah commented Sep 1, 2022

This looks good. Out of curiosity: what was the import time before and after this change on your system?

@eendebakpt
Copy link
Contributor Author

eendebakpt commented Sep 1, 2022

@bjodah Benchmark: time python -c "import time; t0=time.perf_counter(); import symengine; print(f'{1e3*(time.perf_counter()-t0):.2f} [ms]')" results in:

main: 126.40 [ms]
PR: 70.20 [ms]

(linux, python 3.8)

@isuruf isuruf merged commit f931a7b into symengine:master Sep 1, 2022
@bjodah
Copy link
Contributor

bjodah commented Sep 2, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants