Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use web worker for interval #183

Merged
merged 1 commit into from
Oct 14, 2024
Merged

Conversation

smd3256
Copy link
Contributor

@smd3256 smd3256 commented Oct 9, 2024

Add Use Web worker for interval into OCR configuration. It provides stable framerate even when the tab is unfocused by calling setInterval from Web Worker.

Reference:

public/ocr/ocr_main.js Outdated Show resolved Hide resolved
@timotheeg timotheeg merged commit 9ced705 into timotheeg:main Oct 14, 2024
1 check passed
@timotheeg
Copy link
Owner

timotheeg commented Oct 14, 2024

Thanks for the PR! @smd3256 🙏 It is much appreciated.

I have merged it, but only after I made significant changes to it. You can see my new commit here:
0eb8778

Some notes about what I changed:

  • retain a single synchronous semantic to setInterval() and clearInterval(), whether of not the native method or worker is used
  • the worker is the one to track the timer id mappings between the worker timer ids and the main app timer ids
  • no run-time conditional checks for the type of timer used. The new timer system changes atomically by swapping the reference timer. setInterval() and clearInterval() are then methods called on the timer object.
  • The only asynchronous action is the bootstrap wait for the worker to init, this is expected to be very fast.

I've also changed the default value. Your code made using the worker timer default for everyone. I'm not sure I'm OK doing that, versus letting people activating it themselves if they want to try 🤔

That said, we have one chance to do it. Once the code is released, the config will be saved, and so the option "use worker timer" will be explicitly turned off for people.

Because of that, I haven't released yet. I'm still thinking about what I want the default to be first. In my local test, the worker timer seems to work just fine, but I am worried about breaking people's setups, and then I'd have to explain they need to toggle this new setting for them to go back to their old version.

Though I think everyone would be very very happy to not have to deal with the focus alarm LOL 😄 .

I'll make a decision by tomorrow.

@timotheeg
Copy link
Owner

I added one more commit to make the worker initialization a tiny bit more readable too:
9c4d254

@smd3256
Copy link
Contributor Author

smd3256 commented Oct 14, 2024

Thanks for refactoring, the code is now much improved 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants