Giter VIP home page Giter VIP logo

Comments (5)

HarelM avatar HarelM commented on July 18, 2024 1

Looking at the PR I'm guessing that you figured out the answer to your questions, if there's anything that still needs my help let me know. We can continue the discussion in the PR or here, which ever works better for you.
I rewrote the entire actor communication layer, so it should be fairly easy to use it to send a message and get the response back with data.

from maplibre-gl-js.

HarelM avatar HarelM commented on July 18, 2024

The only issue I can think of is the requirement to move the update process into the tile generation in the worker.
i.e. in theory, in the future we want all the manipulation logic of the tiles to happen in the worker and all the data to be stored in something that might not be easy to extract the information from.
Currently the data is duplicated: one copy in the worker is in the tiles and the other copy in an in-memory variable.
Having said that, there's no real progress to move all the logic of update into the tile generation as it requires changes to the geojson-vt package, which chances of seeing this happen are low right now.
To be on the safe side I would recommend getting the data from the worker so that we consider the worker data as the source of truth, and in the future see if we can facilitate getting the data on one hand while keeping on a single copy on the other.
I hope that make sense, if not, let me know.
Otherwise, I don't see any issues with this proposal.

from maplibre-gl-js.

smellyshovel avatar smellyshovel commented on July 18, 2024

The only issue I can think of is the requirement to move the update process into the tile generation in the worker.

Sounds to me like a separate task.

Currently the data is duplicated: one copy in the worker is in the tiles and the other copy in an in-memory variable.

I guess it's the _data field I talk about in the OP. And yes, there's a line which updates it in setData, but there's no such line in updateData, which is expected since in the case with updateData the diff is sent to the worker, not the real "parsed" data. So it seems to me that

  1. this _data field is redundant (I don't really see any usages of it in the main thread code)
  2. even if it's not redundant, it's not updated in updateData, so the code shouldn't rely on it anyway.

Given all that, there currently is a single source of truth: data inside the worker.

To be on the safe side I would recommend getting the data from the worker so that we consider the worker data as the source of truth

Exactly. I think there's no other option anyway.

The question, however, is how. Trying to dive deeper into the source code, but I'm getting confused with between-threads communication.

I can see that the main thread sends requests to the worker thread using the sendAsync method of actor. But how should I send the data back? Should it also be the same (or a similar one) call? Or maybe there's some events-based mechanism?

Namely, what I'm talking about, is the following:

here's the _updateWorkerData method (which is called from either setData and updateData):

async _updateWorkerData(diff?: GeoJSONSourceDiff) {

then it calls (

const result = await this.actor.sendAsync({type: MessageType.loadData, data: options});
) this.actor.sendAsync to send some data to the worker thread.

My question is, whether there's an example somewhere of a vice-versa process? Where a worker needs to send data back to the main thread?


Another thing. There are events like sourcedata which happen after the source data gets updated. Should I do anything about them? Like listening to that event to be fired before responding to the main thread with GeoJSON?

And is it OK for the getData method to be async? As I understnand, it must be, since there is communication in-between threads going on. It's also the case with setData and updateData, but those are not async because 1) interaction is events-based and 2) it doesn't really matter when the data gets set/updated, as we don't really want to do anything with it.

from maplibre-gl-js.

HarelM avatar HarelM commented on July 18, 2024

Another question that came to my mind is what happens if the data is big? So the worker message have a size limit? Is paging needed in that case?

from maplibre-gl-js.

smellyshovel avatar smellyshovel commented on July 18, 2024

Another question that came to my mind is what happens if the data is big? So the worker message have a size limit? Is paging needed in that case?

That's a good question. Didn't think of it as I didn't even know there are limitations regarding the message size. I'll try to check what happens in such cases. Thanks for pointing that out.

from maplibre-gl-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.