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

[Master/Client Connection] Optimize resyncLocalState on Acknowledgment Response #227

Open
GabrielCTroia opened this issue Oct 12, 2024 · 0 comments
Labels
backend Involves server logic client-server sync Client Server Synchronization enhancement New feature or request hacktoberfest Improvements that qualify for Hacktoberfest medium-complexity optimization Improving performance and efficiency.

Comments

@GabrielCTroia
Copy link
Contributor

What:

Currently, when dispatching an Action (emitActionDispatch event), the client and master follow these steps:

  1. The client calculates the next local state and renders it.
  2. The client sends the emitActionDispatch event and waits for the master's acknowledgment, which includes a checksum of the master’s calculated state.
  3. Upon receiving the checksum, the client compares it with the local state’s checksum.
    • If they don't match, the client sends a new request to the master to retrieve the latest master state and waits for the response before rendering it to the UI.

Optimization Proposal:

We can simplify this flow by:

  1. The client calculates the next local state and renders it.
  2. The client sends the emitActionDispatch event, including the local checksum in the payload.
  3. The master calculates the next state and returns it (instead of just the checksum).
  4. The client verifies the checksums in the acknowledgment response:
    • If they match, the process is complete.
    • If they don’t match, the client replaces the local state with the master’s state already present in the response, without sending additional requests.

This reduces the number of round trips and optimizes the flow, while maintaining the real-time rendering experience.

Bonus Optimization:

The master can further optimize by only sending the next state if the checksums differ, reducing unnecessary data transmission.

Why:

This optimization simplifies the flow and reduces network traffic. It also speeds up the synchronization process, as the client can render the correct state faster when there is a mismatch.


Complexity:

Medium to High
This task requires a good understanding of client-server synchronization, real-time communication, and efficient data flow management. The changes must be implemented carefully to ensure no disruptions in the current system behavior.

@GabrielCTroia GabrielCTroia added enhancement New feature or request hacktoberfest Improvements that qualify for Hacktoberfest optimization Improving performance and efficiency. client-server sync Client Server Synchronization backend Involves server logic medium-complexity labels Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Involves server logic client-server sync Client Server Synchronization enhancement New feature or request hacktoberfest Improvements that qualify for Hacktoberfest medium-complexity optimization Improving performance and efficiency.
Projects
None yet
Development

No branches or pull requests

1 participant