mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
update the docs to specify that local agents do not incur serialization overhead (#89)
This commit is contained in:
parent
2b8298d922
commit
baf14cf083
@ -16,10 +16,10 @@ In order for agents to run concurrently, Yew uses [web-workers](https://develope
|
||||
|
||||
#### Reaches
|
||||
|
||||
* Context - There will exist at most one instance of a Context Agent at any given time. Bridges will spawn or connect to an already spawned agent on the UI thread. This can be used to coordinate state between components or other agents. When no bridges are connected to this agent, the agent will disappear.
|
||||
* Job - Spawn a new agent on the UI thread for every new bridge. This is good for moving shared but independent behavior that communicates with the browser out of components. \(TODO verify\) When the task is done, the agent will disappear.
|
||||
* Context - Bridges will spawn or connect to an agent on the UI thread. This can be used to coordinate with state between components or other agents. When no bridges are connected to this agent, the agent will disappear.
|
||||
* Private - Same as Job, but runs on its own web worker.
|
||||
* Public - Same as Context, but runs on its own web worker.
|
||||
* Private - Same as Job, but runs on its own web worker.
|
||||
* Global \(WIP\)
|
||||
|
||||
## Communication between Agents and Components
|
||||
@ -30,11 +30,11 @@ A bridge allows bi-directional communication between an agent and a component. B
|
||||
|
||||
### Dispatchers
|
||||
|
||||
A dispatcher allows uni-directional communication between a component and an agent. A bridge allows a component to send messages to an agent.
|
||||
A dispatcher allows uni-directional communication between a component and an agent. A dispatcher allows a component to send messages to an agent.
|
||||
|
||||
## Overhead
|
||||
|
||||
Agents communicate by serializing their messages using [bincode](https://github.com/servo/bincode). So there is a higher performance cost than just calling functions. Unless the cost of computation or the need to coordinate across arbitrary components will outweigh the cost of message passing, you should contain your logic to functions where possible.
|
||||
Agents that live in their own separate web worker (Private and Public) incur serialization overhead on the messages they send and receive. They use [bincode](https://github.com/servo/bincode) to communicate with other threads, so the cost is substantially higher than just calling a function. Unless the cost of computation will outweigh the cost of message passing, you should contain your logic in the UI thread agents (Job or Context).
|
||||
|
||||
## Further reading
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user