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

Apps with unyielding loops in goroutines hang on web #1416

Open
kkoreilly opened this issue Jan 5, 2025 · 2 comments
Open

Apps with unyielding loops in goroutines hang on web #1416

kkoreilly opened this issue Jan 5, 2025 · 2 comments
Assignees
Labels
bug Something isn't working correctly confirmed This bug has been confirmed
Milestone

Comments

@kkoreilly
Copy link
Member

Describe the bug

See #1407 (reply in thread), golang/go#65178, golang/go#60857.

How to reproduce

See #1407 (reply in thread).

Example code

No response

Relevant output

No response

Platform

macOS

@kkoreilly kkoreilly added bug Something isn't working correctly confirmed This bug has been confirmed labels Jan 5, 2025
@github-project-automation github-project-automation bot moved this to Todo in Bugs Jan 5, 2025
@0pcom
Copy link

0pcom commented Jan 6, 2025

Another possible, though perhaps not practical solution is just to avoid the use of goroutines altogether. I had to do that for such webassembly animations which compile with tinygo because tinygo only supports single-thread usage.

Another perhaps more practical solution might be to use multiple wasm binaries. I do believe that they will execute on different threads but check me on that as I'm not 100% certain.

However, this will likely cause substantial increase in the size of the page resources, possibly doubling the total cumulative size of the wasm binaries. And it might be very complex for core to do that automatically from a source code file for a cogentcore application with core build web && core run web.

...

I opted for the latter approach for a similar globe animation + shopping cart wasm application (not a cogentcore application). When I split the code into two separate files and compiled them each to their own wasm binary, it removed the stutter from the animation which was introduced by the combined source code.

What was very strange in the case I just mentioned, even when other function calls were not executed, but included behind a function that blocked further execution - i.e.:

func main() {

blockingAnimation()

otherFunction()

}

the mere presence of the otherFunction() call - which never executed - caused the animation to stutter every few seconds. Commenting out the function call but leaving the function itself in the code avoided the stutter of the animation.

I have no explanation for that behavior, and it wasn't caused by a goroutine in this case.

@kkoreilly
Copy link
Member Author

kkoreilly commented Jan 11, 2025

@0pcom Thank you for the ideas. Although it is not possible to completely remove goroutines at this time, your idea did give me an idea for how to fix this. Instead of using a separate ad-hoc goroutine for the render loop of a canvas, we will add an OnWindowPaint or similar function, which will allow you to inject functions that occur each time the window is supposed to be rendered, at a 60 FPS rate. That will allow you to accomplish the same functionality without needing a separate goroutine, which will prevent this hanging. (Critically, the main window paint event system that everything depends on has event compression so that it never gets behind on ticks like this).

I will implement and document that when I have the time to do so.

Please also note that #1429 is the long-term complete solution to issues like this.

@kkoreilly kkoreilly self-assigned this Jan 11, 2025
@kkoreilly kkoreilly added this to the v0.4 milestone Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly confirmed This bug has been confirmed
Projects
Status: Todo
Development

No branches or pull requests

2 participants