serverless / serverless-python-requirements

⚡️🐍📦 Serverless plugin to bundle Python packages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make use of compiled .pyc files to speed-up lambda cold starts and further slim the package size

hrist0stoichev opened this issue · comments

Is there an existing issue for this?

  • I have searched existing issues, it hasn't been reported yet

Use case description

Right now slim: true will remove all .pyc and .pyo files but those are actually more useful than .py files for 2 main reasons:

  1. They are smaller in size as compared to .py files.
  2. They will be generated on cold starts anyways, so having them will make cold-starts faster.

Going even deeper, the -OO flag can be used so that .pyo files are even smaller.

Proposed solution (optional)

On this flow chart you can see how the python lookup-mechanism works.

So, the easiest solution would be to just replace all .py files with their .py[c|o] counterparts coming from __pycache__.