kuanyui / Furiganaize

A browser extension allowing the injection of phonetic annotations for Japanese text (furigana) on the fly.
https://addons.mozilla.org/en-US/firefox/addon/furiganaize/
MIT License
64 stars 4 forks source link

Repeating clicking toggle slows down the browser #12

Closed lumynou5 closed 1 year ago

lumynou5 commented 1 year ago

When repeating clicking toggle, the browser notifies that the extension slows down it. Not handling event when still enabling/disabling furigana may prevent this.

kuanyui commented 1 year ago

Impossible.

JavaScript is single threaded. When you clicking, it has only one thread, which will be blocked to process furiganas until finished.

And Web Worker cannot access DOM API so it cannot be used to accelerate the processing in such situation.

2022年10月25日(火) 0:20 Luminous-Coder @.***>:

When repeating clicking toggle, the browser notifies that the extension slows down it. Not handling event when still enabling/disabling furigana may prevent this.

— Reply to this email directly, view it on GitHub https://github.com/kuanyui/Furiganaize/issues/12, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKOPVUC6XEQGAYBDV5IM2LWE2ZMPANCNFSM6AAAAAARNEP4K4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

lumynou5 commented 1 year ago

I don't know. I tried click the button twice quickly. As a result, the page got enable furigana a few seconds later, and then it got disable another few seconds later. Maybe the callback or something else will be triggered still?

kuanyui commented 1 year ago

It's already a callback. Please run a profiler, CPU should be indeedly busy after you clicking.

2022年10月25日(火) 2:43 Luminous-Coder @.***>:

I don't know. I tried click the button twice quickly. As a result, the page got enable furigana a few seconds later, and then it got disable another few seconds later. Maybe the callback or something else will be triggered still?

— Reply to this email directly, view it on GitHub https://github.com/kuanyui/Furiganaize/issues/12#issuecomment-1289445556, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKOPVXTUBE5ZG4MRQH25ALWE3KDRANCNFSM6AAAAAARNEP4K4 . You are receiving this because you commented.Message ID: @.***>

kuanyui commented 1 year ago

In most of case, processing a page should cost about only 1 second or so, even on my mobile phone. Unless the page has too many characters need to be processed.

2022年10月25日(火) 7:59 ooo oop @.***>:

It's already a callback. Please run a profiler, CPU should be indeedly busy after you clicking.

2022年10月25日(火) 2:43 Luminous-Coder @.***>:

I don't know. I tried click the button twice quickly. As a result, the page got enable furigana a few seconds later, and then it got disable another few seconds later. Maybe the callback or something else will be triggered still?

— Reply to this email directly, view it on GitHub https://github.com/kuanyui/Furiganaize/issues/12#issuecomment-1289445556, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKOPVXTUBE5ZG4MRQH25ALWE3KDRANCNFSM6AAAAAARNEP4K4 . You are receiving this because you commented.Message ID: @.***>

lumynou5 commented 1 year ago

The page I used to test has about 15k characters and, so the time to enable/disable is long enough to click the button twice, and in the video the status changed twice exactly. I don't know much about JavaScript, but the result shows it can be triggered.

Screencast from 10-25-2022 03:02:32 PM.webm

kuanyui commented 1 year ago

The example page you've provided ( https://www.sigbus.info/compilerbook ) has 101,523 Japanese characters, which is quite large. I don't think this is an ordinary case.

If you feel this issue really bothers you, please take a look of the source code and try to solve this.

What I can say is in my personal opinion.

  1. I think the blocking is unsolvable in the current mechanism of DOM processing under single thread.
  2. The only possible solution I can think up is lazy-loading, that is to say, only process visible scrollable area when scrolling, but this requires a large modification, I have no free time to do this.

2022年10月25日(火) 15:11 Luminous-Coder @.***>:

The page I used to test has about 15k characters and, so the time to enable/disable is long enough to click the button twice, and in the video the status changed twice exactly. I don't know much about JavaScript, but the result shows it can be triggered.

Screencast from 10-25-2022 03:02:32 PM.webm https://user-images.githubusercontent.com/84374077/197704976-73d622f8-8ada-4a1a-ab00-30cb4807f79d.webm

— Reply to this email directly, view it on GitHub https://github.com/kuanyui/Furiganaize/issues/12#issuecomment-1290090742, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKOPVXFBGL4S7RT56MLPX3WE6BZLANCNFSM6AAAAAARNEP4K4 . You are receiving this because you commented.Message ID: @.***>

kuanyui commented 1 year ago

Latest version (0.6.8) move the sentence analyzer (igo.js) & ruby tagger into a WebWorker (a separated thread) and it should have much better UX.

At least, only DOM processing would block UI now. Demo of single / double clicking:

https://user-images.githubusercontent.com/1370070/200298309-71d7ac6b-7fd5-4425-b4d4-5d6309350e06.mp4

https://user-images.githubusercontent.com/1370070/200299738-c7ad9c1c-7549-4890-a490-a6130ca33b1e.mp4

If you still have performance issue, please send a PR.