[web2py] cost of importing into models vs define functions

106 views
Skip to first unread message

Richard

unread,
Mar 27, 2015, 1:16:18 PM3/27/15
to web...@googlegroups.com
Hello,

I am in the process to move some functions declared kind of globally into models to speed my app since I found it has some important performance penalty to have been too lazy to "modulized" these functions... I would know if importing these functions in models global kind again would lead to the same performance penalty??

Thanks

Richard

Niphlod

unread,
Mar 27, 2015, 5:54:58 PM3/27/15
to web...@googlegroups.com
uhm................you lost me at
"move some function declared kind of globally into models .................... if importing there functions in models global kind"

let's just stick to basics: models are executed at every request. Modules are imported at the first occasion and never again.

Jose

unread,
Mar 29, 2015, 7:53:27 PM3/29/15
to web...@googlegroups.com
Hi

[*1*]
models/
    model1.py
    model2.py
    model3.py
    model4.py

vs

[*2*]
modules/
    model1.py
    model2.py
    model3.py
    model4.py

models/
    model0.py (import model1, model2, model3, model4)


You say [2] is more efficient than [1]?

Richard Vézina

unread,
Mar 29, 2015, 9:03:19 PM3/29/15
to web2py-users
I move functions declared in models... Since all my models files seems to be executed (looking to models_to_run), these functions are accessible from everywhere (globals)...

Now I import all the moved functions in the same models they were commenting the old declarations and I get some speed improvement... So I guess they (functions) are imported only once as you said Niphold...

@Jose, not exactly, more this :

[*Slow*]
models/
  global_functions.py (functions declared old implementation)

[*Faster*]
models/
  global_functions.py (import from modules/global_functions.py)

modules/
  global_functions.py (functions are declared here now)

Richard

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Niphlod

unread,
Mar 30, 2015, 4:01:40 AM3/30/15
to web...@googlegroups.com
[2] imports model1, model2, model3 one time only. those are not re-evaluated. 
[1] also if not "redefining", it still parses the python code at every request. 
Reply all
Reply to author
Forward
0 new messages