Efficiency in compiled appliance

69 views
Skip to first unread message

Scott Hunter

unread,
May 18, 2016, 3:42:50 PM5/18/16
to web2py-users
The web2py book, under Efficiency Tricks, says:

  • Do not put many functions in the same controller but use many controllers with few functions.
When an appliance is compiled, each of the functions is compiled into its own .pyc file, the same as would happen if they were in different functions (although the names will differ).  So does the above recommendation only apply to non-compiled appliances?

Note that one of the earlier recommendations is:

  • Bytecode compile your app using admin.
-Scott

Niphlod

unread,
May 18, 2016, 5:02:35 PM5/18/16
to web2py-users
what would be the counter-arg here ? 

Scott Hunter

unread,
Oct 25, 2016, 10:31:31 AM10/25/16
to web2py-users
Not clear what you are asking.

If compiling an app results in each function being in its own file whether they came from distinct source files or not, what is the benefit to having each function start off in its own file?

- Scott

Anthony

unread,
Oct 26, 2016, 12:38:58 AM10/26/16
to web2py-users
On Wednesday, May 18, 2016 at 3:42:50 PM UTC-4, Scott Hunter wrote:
The web2py book, under Efficiency Tricks, says:

  • Do not put many functions in the same controller but use many controllers with few functions.
When an appliance is compiled, each of the functions is compiled into its own .pyc file, the same as would happen if they were in different functions (although the names will differ).  So does the above recommendation only apply to non-compiled appliances?

Each function gets its own .pyc file, but that .pyc file contains a copy of the entire controller -- the only difference between each of the .pyc files is the very last line, which has the form:

response._vars = response._caller(the_function_that_was_called)

So, even with compiled controllers, there will likely still be some benefit to keeping the controllers smaller (though less benefit than with non-compiled controllers).

Anyway, I would probably let organizational rather than efficiency considerations dictate what's in each controller. Chances are, excessively large controller files also indicate poor code/routing organization. If you keep your code well organized and your URL routes sensible, you probably won't have a lot of large controllers.

Note, you can also reduce controller line count by moving some of the logic into modules and importing (this will be even more efficient than compiling, as once a module has been imported, it doesn't need to be re-read at all).

Anthony
Reply all
Reply to author
Forward
0 new messages