Closed guillett closed 12 months ago
Oh sorry, I forgot to give more context. I updated the initial comment.
Thank you for this changeset! I don't understand enough of the goals of the introspection nor of the suggested alternative code to approve or request changes. I like how less parameters are needed with that rewrite. Could you maybe share some data on that “much quicker startup time”? 🙂
@MattiSG Every variable has formulas, which are not defined in core but directly in each country package. For core to be able to use these formulas, the Variable
class parses ~the AST, their internal sub-Python representation~ the source code verbatim from the files where these formulas are defined, and evaluates them, so they get defined in memory. (This is one of the reasons static analysis of OpenFisca at run-time is not possible: the formulas refered to internally have no tie with the actual code read from the packages source files).
@guillett What does it imply that no longer have parameters as well as calling functions? What I could get from the changeset is that comments are no longer parsed (why were there being parsed is yet as mistery for me).
If you could add more specific information about the actual changes it would be great :)
If I'm not mistaken, @benjello @eraviart this mechanism bypasses all compile-time and interpreter optimisations.
Another possible concern is that performance scales badly (time increases exponentially the bigger a country package).
Maybe @Morendil looked into this or @fpagnoux?
Python version bump made OpenFisca Web API much much slower. It takes 5 minutes or so (cf discussion on Slack).
This slow startup is mainly due to the introspection data generation and more precisely to the python files parsing.
before
after
similar to #1188
Breaking changes
get_introspection_data
no longer have parameters as well as calling functionsTechnical notes
I think it is worth sharing my development strategy:
I worked with a country package (France) and started
gunicorn run --config config.py
withcountry_package = 'openfisca_france'
tax_benefit_system = build_tax_benefit_system( country_package_name = country_package, extensions = [], reforms = [] )
application = create_app(tax_benefit_system)
It allowed me to get visual clues with snakeviz on areas of potential improvements (as well as slow interesting portions I could comment out).
I also cloned https://github.com/python/cpython to have a better understanding of underlying functions. However, I didn't dig much in code in C I mainly stayed in Python and I recycled code snippets in our contexts.