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

Efficiently route messages through HocuspocusProviderWebsocket #727

Merged
merged 2 commits into from
Oct 16, 2023

Conversation

raineorshine
Copy link
Contributor

@raineorshine raineorshine commented Oct 15, 2023

This PR changes the provider's onMessage running time from O(n) to O(1), where n is the number of all attached providers. It does this by adding a Map to the HocuspocusProviderWebsocket configuration that allows O(1) lookup of attached providers by document name. It will then manually call onMessage on the appropriate provider and only that provider.

Fixes #724

@raineorshine
Copy link
Contributor Author

I still need to test in the playground and my app, but it should be okay. Ended up being a very simple change.

@raineorshine raineorshine marked this pull request as ready for review October 16, 2023 15:26
@raineorshine
Copy link
Contributor Author

raineorshine commented Oct 16, 2023

Works great in my app, and seems to be working in the playground (other than the Awareness section which is broken in main).

I haven't done any measurements, but in my app this results in a massive reduction in client-side memory usage when many Docs are synced at once. Completely fixed the out-of-memory error that was crashing my web worker.

Ready for review/merge.

@janthurau
Copy link
Collaborator

Thanks a lot for this! Looks great, will do a round of testing as well and then get this merged 😎

@janthurau janthurau merged commit ff88145 into ueberdosis:main Oct 16, 2023
3 checks passed
TalhaASiddiqi pushed a commit to educative/hocuspocus that referenced this pull request Feb 1, 2024
…dosis#727)

* Efficiently route messages through HocuspocusProviderWebsocket (ueberdosis#724).

* HocuspocusProviderWebsocket: Use peekVarString to check documentName.
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.

onMessage is inefficiently called on every Doc
2 participants