local-cdn
local-cdn copied to clipboard
Optimize the code
There is a lot of other noise in this commit, which you don't want to backport, but also quite a few optimizations: https://github.com/kurtextrem/local-cdn/commit/c1370bfdcc1e3f0431bfba4907e2ab3cad7fbdf9
a) V8 needs to compile the regex each time the callback function of chrome.webRequest.onBeforeRequest.addListener
is called. Declare the regexes outside the cb function to improve performance.
b) Cache flattenObject responses. The for..in loop isn't exactly cheap to do. See here: https://github.com/kurtextrem/local-cdn/blob/c1370bfdcc1e3f0431bfba4907e2ab3cad7fbdf9/src/common.js#L32 & https://github.com/kurtextrem/local-cdn/blob/c1370bfdcc1e3f0431bfba4907e2ab3cad7fbdf9/src/common.js#L43
c) Cache getURL. Extension URL won't change as long as the background is active.
d) Make the chrome.webRequest.onBeforeRequest.addListener
CB fn an own function - like function callback(data)
, this makes the extension more testable (test commit here
https://github.com/kurtextrem/local-cdn/commit/63d60bfe6aa93353ed927a532ef5cb1e69d9061d)
(e) I haven't seen any adverse effects, so removing hasOwnProperty
from the for..in loop improves performance)
@kurtextrem can you prepare a pull request.
Sorry for the late response, I was in holidays. Still want the PR? Although I'm not sure how I'd do that (new branch in my fork and then PR from there?)
I've done a few optimizations based on your comments. Get the new code, and modify it if you still have ideas to improve the performance then request a pull merge.
https://help.github.com/articles/about-pull-requests/
@james-fray, c’mmon, make this fork shine again!