Changes between Version 55 and Version 56 of DeveloperGuidelines/Optimisation
- Timestamp:
- 08/30/10 12:58:20 (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DeveloperGuidelines/Optimisation
v55 v56 31 31 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) 32 32 33 == = Specific Examples ===34 === = Python ====33 == Specific Examples == 34 === Python === 35 35 NB These vary on cases, so use the Profiler to see how they work in your cases... 36 36 {{{ … … 107 107 108 108 Hence - 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 === 126 111 127 112 These "rules" might seem a matter of course, however, sometimes you need to take a second look at your code: 128 113 * Insert a temporary {{{print >> sys.stderr, self.query}}} into web2py's {{{select()}}} function and take a look at what it says. 129 114 130 === Use Joins===115 ==== Use Joins ==== 131 116 132 117 One complex query is usually more efficient than multiple simple queries (and gives the DB server a chance to optimize): … … 147 132 }}} 148 133 149 === Limit your Query===134 ==== Limit your Query ==== 150 135 151 136 Ask exactly for what you expect - if you expect only one result, then limit the search by limitby: … … 173 158 }}} 174 159 175 === Don't ask twice...===160 ==== Don't ask twice... ==== 176 161 177 162 ...for the same record. Look down your code whether you need the same record again later: … … 192 177 }}} 193 178 194 === Don't loop over Queries===179 ==== Don't loop over Queries ==== 195 180 196 181 ...if you can avoid it: … … 255 240 }}} 256 241 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 257 256 ---- 258 257 DeveloperGuidelines