wbond / pybars3

Handlebars.js template support for Python 3 and 2
GNU Lesser General Public License v3.0
179 stars 46 forks source link

Module is very slow to import #74

Open silverwind opened 2 years ago

silverwind commented 2 years ago

On my machine, it takes over 400ms to import pybars:

$ PYTHONPROFILEIMPORTTIME=1 python -c 'import pybars' |& grep pybars                                                                          
import time:       209 |        209 |     pybars._templates
import time:    203090 |     410008 |   pybars._compiler
import time:       383 |     410390 | pybars
wbond commented 2 years ago

This is almost certainly due to the current architecture of using PyMeta and compiling the grammar when importing pybars._compiler.

I had originally had interest in rewriting the project to use a different parser (https://github.com/wbond/handlebars.py), but at this point I have too many projects to work on, so I don't foresee working on this any time soon. If there was some strong interest for this, and some corporate sponsors interested in backing the work, I might reconsider.

wbond commented 2 years ago

Actually, it is possible that the compiled grammar could be serialized into a file on each release. That may give it enough of a performance boost. Perhaps that is something you could look into?

silverwind commented 2 years ago

Not sure I'm motivated enough, Python is not my lingua franca. We definitely feel the pain of this import time thought, as it's used during short-lived processes, so I'm not saying I won't eventually get motivated :)

zaafar commented 2 years ago

Actually, it is possible that the compiled grammar could be serialized into a file on each release.|

do you mean via the CI (Github Actions) pipeline & source code modification?