Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: chrome/common/extensions/docs/templates/intros/events.html

Issue 13523005: Performance guidelines for decl. WebRequest API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added examples Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/docs/templates/intros/declarativeWebRequest.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <p> 1 <p>
2 An <code>Event</code> is an object 2 An <code>Event</code> is an object
3 that allows you to be notified 3 that allows you to be notified
4 when something interesting happens. 4 when something interesting happens.
5 Here's an example of using the 5 Here's an example of using the
6 <code>chrome.tabs.onCreated</code> event 6 <code>chrome.tabs.onCreated</code> event
7 to be notified whenever there's a new tab: 7 to be notified whenever there's a new tab:
8 </p> 8 </p>
9 9
10 <pre> 10 <pre>
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 157
158 <pre> 158 <pre>
159 var rule_ids = ["id1", "id2", ...]; 159 var rule_ids = ["id1", "id2", ...];
160 function getRules(rule_ids, function callback(details) {...}); 160 function getRules(rule_ids, function callback(details) {...});
161 </pre> 161 </pre>
162 162
163 <p> 163 <p>
164 The <code>details</code> parameter passed to the <code>callback()</code> functio n 164 The <code>details</code> parameter passed to the <code>callback()</code> functio n
165 refers to an array of rules including filled optional parameters. 165 refers to an array of rules including filled optional parameters.
166 </p> 166 </p>
167
168 <h3 id="performance">Performance</h3>
169
170 <p>
171 To achieve maximum performance, you should keep the following guidelines in
172 mind:
173 <ul>
174 <li><p>Register and unregister rules in bulk. After each
175 registration or unregistration, Chrome needs to update internal data
176 structures. This update is an expensive operation.</p>
177 <p>Instead of</p>
178 <pre>
179 var rule1 = {...};
180 var rule2 = {...};
181 chrome.declarativeWebRequest.onRequest.addRules([rule1]);
182 chrome.declarativeWebRequest.onRequest.addRules([rule2]);</pre>
183 <p>prefer to write</p>
184 <pre>
185 var rule1 = {...};
186 var rule2 = {...};
187 chrome.declarativeWebRequest.onRequest.addRules([rule1, rule2]);</pre>
188 <li>Prefer substring matching over matching using regular expressions in a
189 $ref:events.UrlFilter. Substring based matching is extremely fast.
190 <p>Instead of</p>
191 <pre>
192 var match = new chrome.declarativeWebRequest.RequestMatcher({
193 url: {urlMatches: "example.com/[^?]*foo" } });</pre>
194 <p>prefer to write</p>
195 <pre>
196 var match = new chrome.declarativeWebRequest.RequestMatcher({
197 url: {hostSuffix: "example.com", pathContains: "foo"} });</pre>
198 <li>If you have many rules that all share the same actions, you may merge
199 the rules into one because rules trigger their actions as soon as a single
200 condition is fulfilled. This speeds up the matching and reduces memory
201 consumption for duplicate action sets.
202 <p>Instead of</p>
203 <pre>
204 var condition1 = new chrome.declarativeWebRequest.RequestMatcher({
205 url: { hostSuffix: 'example.com' } });
206 var condition2 = new chrome.declarativeWebRequest.RequestMatcher({
207 url: { hostSuffix: 'foobar.com' } });
208 var rule1 = { conditions: [condition1],
209 actions: [new chrome.declarativeWebRequest.CancelRequest()]};
210 var rule2 = { conditions: [condition2],
211 actions: [new chrome.declarativeWebRequest.CancelRequest()]};
212 chrome.declarativeWebRequest.onRequest.addRules([rule1, rule2]);</pre>
213 <p>prefer to write</p>
214 <pre>
215 var rule = { conditions: [condition1, condition2],
216 actions: [new chrome.declarativeWebRequest.CancelRequest()]};
217 chrome.declarativeWebRequest.onRequest.addRules([rule]);</pre>
218 </ul>
219 </p>
167 </div> 220 </div>
168 {{/is_apps}} 221 {{/is_apps}}
169 222
170 {{^is_apps}} 223 {{^is_apps}}
171 <div class="doc-family extensions"> 224 <div class="doc-family extensions">
172 <h2 id="filtered">Filtered events</h2> 225 <h2 id="filtered">Filtered events</h2>
173 226
174 <p>Filtered events are a mechanism that allows listeners to specify a subset of 227 <p>Filtered events are a mechanism that allows listeners to specify a subset of
175 events that they are interested in. A listener that makes use of a filter won't 228 events that they are interested in. A listener that makes use of a filter won't
176 be invoked for events that don't pass the filter, which makes the listening 229 be invoked for events that don't pass the filter, which makes the listening
(...skipping 26 matching lines...) Expand all
203 of filters that an event supports will be listed in the documentation for that 256 of filters that an event supports will be listed in the documentation for that
204 event in the "filters" section.</p> 257 event in the "filters" section.</p>
205 258
206 <p>When matching URLs (as in the example above), event filters support the same 259 <p>When matching URLs (as in the example above), event filters support the same
207 URL matching capabilities as expressible with a 260 URL matching capabilities as expressible with a
208 $ref:events.UrlFilter, except for scheme and port 261 $ref:events.UrlFilter, except for scheme and port
209 matching.</p> 262 matching.</p>
210 263
211 </div> 264 </div>
212 {{/is_apps}} 265 {{/is_apps}}
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/templates/intros/declarativeWebRequest.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698