MolSSI / QCFractal

A distributed compute and database platform for quantum chemistry.
https://molssi.github.io/QCFractal/
BSD 3-Clause "New" or "Revised" License
148 stars 48 forks source link

Lazy-load pandas #855

Closed mattwthompson closed 2 weeks ago

mattwthompson commented 3 weeks ago

Description

Currently, a little less than half of the time taken to import anything from QCPortal is spend dealing with Pandas. I think most use cases don't involve its direct use, so it can be loaded later when needed. This improvement should propagate to downstream packages which want to i.e. use PortalClient or build off of record models but don't need Pandas.

Before:

$ hyperfine \                                                                    14:31:18  ☁  4ebcd88f ☀
    'python -c "from qcportal import PortalClient"' \
    --prepare \
    'python -c "from qcportal import PortalClient"'
Benchmark 1: python -c "from qcportal import PortalClient"
  Time (mean ± σ):     621.8 ms ±  10.0 ms    [User: 514.2 ms, System: 96.5 ms]
  Range (min … max):   608.4 ms … 642.9 ms    10 runs
$ python -X importtime -c "from qcportal import PortalClient" 2> tuna.log && tuna tuna.log

image

With these changes:

$ fc                                                                     14:27:45  ☁  lazy-load-pandas ☀
hyperfine \
    'python -c "from qcportal import PortalClient"' \
    --prepare \
    'python -c "from qcportal import PortalClient"'
Benchmark 1: python -c "from qcportal import PortalClient"
  Time (mean ± σ):     375.1 ms ±   7.5 ms    [User: 318.7 ms, System: 50.1 ms]
  Range (min … max):   368.1 ms … 394.3 ms    10 runs

Status

bennybp commented 2 weeks ago

Sounds good to me.

I think the CI errors are from conda resolving some older pytest version with python 3.8. Since python 3.8 is now EOL, I can probably take that out of the CI. Would you agree?

mattwthompson commented 2 weeks ago

Sure, I've made an attempt in https://github.com/MolSSI/QCFractal/pull/856

bennybp commented 2 weeks ago

Thanks! This is great, I'm always looking for performance increases