Lazy Loading for Forms?

I drastically reduced my startup time with the routing module from Anvil Extras this way:

  • split each form into two forms, one lightweight that contains only the routing info and one heavyweight that does all the work.
  • Importing the lightweight form in the @routing.main_router module is then fast
  • the lightweight form lazily imports the heavyweigh form

Example:

@routing.route(ACCOUNTS_URL_PATH, title='Accounts')
class Accounts(AccountsTemplate):
  def __init__(self, **properties):
    # lazy import of the heavyweight form
    from ..AccountsComponent import AccountsComponent
    self.add_component(AccountsComponent())
7 Likes