Pymongo lib import is slow

One workaround to alleviate the cost of a cold start could be to configure Lambda with provisioned concurrency.

You could also install pymongo from the source without the C extensions which reduces the improt time to 74ms on my machine. Without the C extensions pymongo will be slower in general so you may want to see if that affects your application:

$ NO_EXT=1 pip install --no-binary=":all:" pymongo
Collecting pymongo
  Using cached pymongo-4.6.2-py3-none-any.whl
Collecting dnspython<3.0.0,>=1.16.0 (from pymongo)
  Downloading dnspython-2.6.1.tar.gz (332 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 332.7/332.7 kB 13.2 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: dnspython
  Building wheel for dnspython (pyproject.toml) ... done
  Created wheel for dnspython: filename=dnspython-2.6.1-py3-none-any.whl size=307696 sha256=5ef3b9680161f6fa89daf8ad451b5f1a33b18ae8a1c6778cdf4b43f08c0a6e50
  Stored in directory: /Users/shane/Library/Caches/pip/wheels/64/7a/78/c66f17167e54a96b77bebd0a18414c9183788ae2f8c4a12e2a
Successfully built dnspython
Installing collected packages: dnspython, pymongo
Successfully installed dnspython-2.6.1 pymongo-4.6.2
$ python3 -X importtime -c "import pymongo" 2> import-pymongo-no-C.log
$ tuna import-pymongo-no-C.log