Skip to content

Extract MainLoop out of Browser #12165

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

Closed
wants to merge 4 commits into from

Conversation

curiousdannii
Copy link
Contributor

@curiousdannii curiousdannii commented Sep 11, 2020

Fixes #5355

I just noticed that Asyncify mode requires MainLoop, but not because of anything inherent in Asyncify mode, but just because it needs to be aware of it. It would be great if Asyncify could handle MainLoop if it's included, but to not require it. Not too sure how to do that though. Trying a simple typeof MainLoop !== 'undefined'

Similarly, MainLoop.safeSetTimeout could be split out into an even smaller library, so that if all you use is emscripten_sleep it wouldn't have to include all of MainLoop? Edit: This was very easy actually.

@curiousdannii
Copy link
Contributor Author

There are a few errors that I couldn't make sense of :/

@sbc100
Copy link
Collaborator

sbc100 commented Sep 11, 2020

Nice! Thanks for working on this.

Can we maybe break this down into smaller changes so it more obvious if there are any actual changes here of it is NFC.

To start with how about splitting out just the safetimers part? That seems like it might be separable.

var LibrarySafeTimers = {
$SafeTimers__postset: 'Module["requestAnimationFrame"] = function Module_requestAnimationFrame(func) { SafeTimers.requestAnimationFrame(func) };\n',
$SafeTimers: {
// abort and pause-aware versions TODO: build main loop on top of this?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we take this object's 7 member as make them into top level library members?

That way a program that only needs safeSetTimeout would depend only on that one functuion.

Of course each of the function would need to depend on allowAsyncCallbacks and queuedAsyncCallbacks so maybe that could be done with autoAddDeps?

Copy link
Contributor Author

@curiousdannii curiousdannii Sep 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Should they all be prefixed with emscripten_?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, these are library internal so should be prefixed with $.

Anything without a $ is visible as a C/C++ and we don't want that in this case I think.

The $ is only need in the __deps and on the decl itself.. When you call the function you don't need the $.

@@ -0,0 +1,118 @@
/**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can come up with a better name for this library? I'm not really sure what "safe timers" means. Do you know the history of this name or what it really means?

Copy link
Contributor Author

@curiousdannii curiousdannii Sep 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they're "safe" in that the callbacks won't be run (immediately) if it's paused, or if the module has aborted. Though at present nothing actually calls the pause/resume functions. That functionality could be cut? (And readded later if it ever was needed.)

@curiousdannii
Copy link
Contributor Author

curiousdannii commented Sep 11, 2020

Nice! Thanks for working on this.

Can we maybe break this down into smaller changes so it more obvious if there are any actual changes here of it is NFC.

To start with how about splitting out just the safetimers part? That seems like it might be separable.

Sure, that makes sense.

These changes shouldn't effect the public/published API, but if anyone has manually gone and looked up the source and added calls to the internal functions it would break. Would it be worth turning the old functions into wrappers of the new with assertion warnings?

@curiousdannii curiousdannii marked this pull request as draft September 11, 2020 22:46
kripken pushed a commit that referenced this pull request Sep 13, 2020
Instead, check if Browser exists or not, and add direct dependencies on
Browser from the specific async wget methods that actually need full
Browser support.

Split out from #12165

Saves 13KB from a minified build.
@kripken
Copy link
Member

kripken commented Sep 15, 2020

Would it be worth turning the old functions into wrappers of the new with assertion warnings?

For an internal API I think that's probably not needed.

Base automatically changed from master to main March 8, 2021 23:49
@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Apr 16, 2022
@stale stale bot closed this Jul 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Separate Browser.mainLoop from the browser API functions
3 participants