andreicristianpetcu / google_translate_this

This WebExtension translates the current page with Google Translate. It does so on demand so it does not change the page unless the user selected this. It is fast, light and privacy friendly.
https://github.com/andreicristianpetcu/google_translate_this/releases
GNU General Public License v3.0
190 stars 10 forks source link

Why consume a lot of performance? #18

Closed nY381v closed 5 years ago

nY381v commented 5 years ago

Looking at Firefox's performance through "about:performance", I found that "Google Translate This Page" takes up a lot of performance (when loading a new page, and this page doesn't trigger it), second only to "Tampermonkey". This surprised me a lot. I always thought that "Google Translate This Page" is roughly equivalent to a "button" and does not affect the performance of the browser.

Is this reasonable?

andreicristianpetcu commented 5 years ago

Strange. That is what I thought also, and I wrote it :D Any chance you can record a perf profile and share the link with me?

https://vimeo.com/269371096

https://vimeo.com/269371201

andreicristianpetcu commented 5 years ago

It might be the fact that it changes the CSP for the current page if it uses CSP but that should be reallt limmited.

andreicristianpetcu commented 5 years ago

Here is my perf profile on my main profile https://perfht.ml/2Jw358C for me it really does not use a lot

nY381v commented 5 years ago

Thank you for your reply. https://perfht.ml/31S1NLD

I disabled CSP. "curity.csp.enable":"false" "security.csp.enable":"false"

And I use the "-marionette" mode to control firefox.

andreicristianpetcu commented 5 years ago

Disabling CSP does not help. CSP is a way in which a server tells a browser "please run file1.js, file2.js and file3.css". The browser banns everything else, including stuff from translate.google.com :disappointed:

This is good for security but bad for me. On every page load I say: "wait browser, please allow file1.js, file2.js, file3.css aaaaaand translate.google.com"

This seems to take a bit of time :disappointed: As you can see the code that does this is non-trivial https://github.com/andreicristianpetcu/google_translate_this/blob/194e404cd6d8683140f945afa656db669cc3e0a7/scripts/background.js#L101-L149

I will investigate more when I get a bit of time.

andreicristianpetcu commented 5 years ago

Hmmm.... my assumption was wrong. It seems like updateMenuForDomain is causing all the fuss.

It seems to have a very small portion of the performance issue. image

Check out my filter on your data. I'm looking at what the WebExtension process is doing. My extension is not doing anything in other processes. Google translate is doing some heavy work on demand in the content process but that should not be an issue since it's on demand.

Go ahead, play with the data.... maybe drill down into a specific section or period of time that I missed. https://perfht.ml/349ucyb

nY381v commented 5 years ago

I created a new configuration and only loaded one extension.

https://youtu.be/GGonFCIfAOw

andreicristianpetcu commented 5 years ago

Brand new profile. Your use case with different web sites. Here is the data. https://perfht.ml/36cjCIF Will try to investigate the usage of these methods. Will report back.

nY381v commented 5 years ago

I have a doubt, can it be used in the form of a Tampermonkey script?

andreicristianpetcu commented 5 years ago

Hmmmm. I will look into this. It will not work for sure on pages with CSP 😞

I made a fix for the perf issue but I cannot ship new updates to the extension.

nY381v commented 5 years ago

Thank you. Where can I find new xpi files?

andreicristianpetcu commented 5 years ago

I cannot ship new versions :( you have to build it yourself https://github.com/andreicristianpetcu/google_translate_this/issues/19

I will publish an unsigned xpi file once I get to my laptop but not a signed one.

andreicristianpetcu commented 5 years ago

Try this. It's not signed so you need to disable xpi signing. tr_desktop.zip

nY381v commented 5 years ago

Thanks. But even if I disable extension verification, it still can't be installed.

andreicristianpetcu commented 5 years ago

Hmm. It works for me. I made a new profile in Firefox Nightly from about:profiles. I flipped the xpinstall.signatures.required to false in about:config then renamed tr_desktop.zip to tr_desktop.xpi (github does not allow xpi attachments here for some reason) and dragged the xpi on the Firefox window. Hit Ok and it worked. @LArctic

nY381v commented 5 years ago

Yes, but this is only valid in the "nightly" version.

yoasif commented 5 years ago

It should also work in developer edition: https://www.mozilla.org/firefox/developer/

andreicristianpetcu commented 5 years ago

It should work in DevEdition also which is awesome