Changes between Version 55 and Version 56 of DeveloperGuidelines/Optimisation


Ignore:
Timestamp:
08/30/10 12:58:20 (14 years ago)
Author:
Fran Boon
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/Optimisation

    v55 v56  
    3131 7. Consider having configurations which are read from DB frequently but written-to rarely, be set in configuration files which are written-out from the DB (like the CSS from themes)
    3232
    33 === Specific Examples ===
    34 ==== Python ====
     33== Specific Examples ==
     34=== Python ===
    3535NB These vary on cases, so use the Profiler to see how they work in your cases...
    3636{{{
     
    107107
    108108Hence - for dicts, avoid hasattr to test for containment.
    109 ==== !JavaScript ====
    110 !JavaScript string concatenation:
    111  * http://aymanh.com/9-javascript-tips-you-may-not-know#String_Concatenation_vs._Array.join
    112 
    113 === Profiling ===
    114  * Web2Py can [http://www.mail-archive.com/web2py@googlegroups.com/msg06267.html use cProfile]:
    115   * {{{web2py.py -F profiler.log}}}
    116   * or if running as service, edit {{{options.py}}}: {{{profiler_filename = 'profiler.log'}}}
    117  * http://docs.python.org/library/profile.html
    118  * http://www.cherrypy.org/wiki/Testing#Profiling
    119  * http://mg.pov.lt/profilehooks/
    120  * YSlow plugin for Firebug: http://developer.yahoo.com/yslow/
    121  *  You can also use [http://www.pylot.org Pylot] to test the application's behavior under load, and get more reliable results (+ in a nicer report form).
    122 
    123 
    124 
    125 == Golden Rules for DB Queries ==
     109
     110=== Golden Rules for DB Queries ===
    126111
    127112These "rules" might seem a matter of course, however, sometimes you need to take a second look at your code:
    128113  * Insert a temporary {{{print >> sys.stderr, self.query}}} into web2py's {{{select()}}} function and take a look at what it says.
    129114
    130 === Use Joins ===
     115==== Use Joins ====
    131116
    132117One complex query is usually more efficient than multiple simple queries (and gives the DB server a chance to optimize):
     
    147132}}}
    148133
    149 === Limit your Query ===
     134==== Limit your Query ====
    150135
    151136Ask exactly for what you expect - if you expect only one result, then limit the search by limitby:
     
    173158}}}
    174159
    175 === Don't ask twice... ===
     160==== Don't ask twice... ====
    176161
    177162...for the same record. Look down your code whether you need the same record again later:
     
    192177}}}
    193178
    194 === Don't loop over Queries ===
     179==== Don't loop over Queries ====
    195180
    196181...if you can avoid it:
     
    255240}}}
    256241
     242=== !JavaScript ===
     243!JavaScript string concatenation:
     244 * http://aymanh.com/9-javascript-tips-you-may-not-know#String_Concatenation_vs._Array.join
     245
     246== Profiling ==
     247 * Web2Py can [http://www.mail-archive.com/web2py@googlegroups.com/msg06267.html use cProfile]:
     248  * {{{web2py.py -F profiler.log}}}
     249  * or if running as service, edit {{{options.py}}}: {{{profiler_filename = 'profiler.log'}}}
     250 * http://docs.python.org/library/profile.html
     251 * http://www.cherrypy.org/wiki/Testing#Profiling
     252 * http://mg.pov.lt/profilehooks/
     253 * YSlow plugin for Firebug: http://developer.yahoo.com/yslow/
     254 *  You can also use [http://www.pylot.org Pylot] to test the application's behavior under load, and get more reliable results (+ in a nicer report form).
     255
    257256----
    258257DeveloperGuidelines