Skip to content

[WIP] Multithreaded rendering #603

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 116 commits into from
Closed

[WIP] Multithreaded rendering #603

wants to merge 116 commits into from

Conversation

avaer
Copy link
Member

@avaer avaer commented Nov 20, 2018

Fixes #382.
Fixes #130.

This PR implements multithreaded rendering in Exokit. The goal is to break out every window context into its own thread of execution, which runs in parallel with all others.

Reasoning

  • Bugs: The first reason to do this is that the existing window and Worker implementations, vm-one and window-worker, are custom hacks that reimplement the node tick loop. In addition to a history of platform-specific Worker bugs in implementing importScripts, this interacts badly with some native node code in e.g. the TLS implementation, necessitating more out-of-thread routing hacks. All of these problems go away if we just use first-class worker_threads, with native node support that does not need to be tracked or debugged.

  • Starvation: The way the current tick loop works, the window tick execution is the only place that window contexts can make forward progress in libuv. That means that receiving request data is actually tied to the frame rate of the system -- this manifests as an inexplicable network slowness during loading. This is just how uv_run works by default, and trying to schedule work on the window instances is a problem that's 100% solved for us if we use worker_threads.

  • Performance: The way the current tick loop works, we run each window serially in the main loop (no other way to do it, since all windows are bound to the same thread). By removing this restriction, we can run all window raf ticks, and therefore rendering, in parallel. This especially helps in the case of reality tabs, where we potentially have many render layers in the same renderloop, all of which can logically run independently. Even if you don't care about reality tabs, this is nonetheless a performance improvement for the single-window case, since Exokit's main loop itself can now run in parallel with your window.

  • Future features: This paves the way for more futuristic features such as desynching misbehaving reality tab layers and correcting the blend with a userspace reprojection.

Implementation

This requires Node 11 for worker_threads stability. Most notably, this required a port of libnode.a for arm64/Magic Leap.

Additionally, this completely rewrites vm-one and window-worker in terms of worker_threads.

Finally, this PR requires some light synchronization where the Exokit renderloop needs to access/call into the rafs and events of the window instances.

Dependent PRs

Ingests avaer/window-worker@ed59b8d, avaer/vm-one#4.

@avaer
Copy link
Member Author

avaer commented Nov 20, 2018

  • Still need to hook in the render loop's window.requestAnimationFrame map/join and global access

@avaer avaer force-pushed the multithread branch 4 times, most recently from 398cbb6 to 1acd002 Compare November 26, 2018 00:08
@avaer avaer force-pushed the multithread branch 3 times, most recently from 4c6c5fd to c96391f Compare December 6, 2018 02:55
@avaer
Copy link
Member Author

avaer commented May 9, 2019

The work in this branch is outdated. All of this functionality has moved forward with #760.

@avaer avaer closed this May 9, 2019
@avaer avaer deleted the multithread branch August 5, 2019 22:20
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.

Use Node workers Multiprocess iframe
1 participant