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

Break up tight coupling between worker and rendering logic and state #8311

Open
mourner opened this issue Jun 1, 2019 · 0 comments
Open
Labels
performance ⚡ Speed, stability, CPU usage, memory usage, or power usage refactoring 🏗️

Comments

@mourner
Copy link
Member

mourner commented Jun 1, 2019

Historically, most internal GL JS classes had mixed responsibilities, doing both worker and main thread work and sharing tons of state in between. #5143 removed a lot of serialization boilerplate to make it easier to transfer class instances, but also made the situation harder to control — internal state is now shared between threads implicitly and we haven't really paid close attention to how much of it is necessary to share. There were targeted fixes for the worst bottlenecks (see PRs linked in #7011), but the general problem remains — deserialization on the main thread still takes noticeable CPU time (some of it not shown in profiles because JSON structured cloning with postMessage isn't attributed explicitly).

Additionally, the logic is so tangled now that makes it very hard to understand which of it happens on the main thread, which is on the worker side, and which should be shared intentionally. This contributes to the worker bundle being almost as big as the main thread one, increasing time-to-first-render.

So let's discuss what we could do to address this. I think that since our goal is to eventually minimize logic and state sharing and tight coupling between threads, we should:

  • Revert back to explicit serialization.
  • Switch to raw buffer transfer instead of class instances where possible.
  • Start breaking up various classes like layer buckets into separate ones (render-side and worker-side).

The clearer and more explicit the separation between render-side and worker-side logic, and between shared, temporary and persistent state, the better.

I'm not sure how this correlates with GL Native codebase (especially given that there are considerable architectural differences) (cc @kkaefer), but we've accumulated a lot of technical debt on this front in GL JS and I'd love to see if we could address it this year.

cc @mapbox/gl-js

@mourner mourner added performance ⚡ Speed, stability, CPU usage, memory usage, or power usage refactoring 🏗️ labels Jun 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance ⚡ Speed, stability, CPU usage, memory usage, or power usage refactoring 🏗️
Projects
None yet
Development

No branches or pull requests

1 participant