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

Fake socket that doesn't need serializing/deserializing #195

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

martinRenou
Copy link
Member

Currently, the mock-socket's WebSocket needs a string to be passed through the "fake wire". This means we need to serialize messages, pass them through the wire, then deserialize.

Instead, it would be faster and more robust to be able to pass the original message through, without any serialization involved.

/*
* Send an IMessage through the socket
*/
sendMessage (data: KernelMessage.IMessage) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more or less a copy of WebSocket.send only that it doesn't force the data to be a string

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead it passes the KernelMessage.IMessage without touching it

@martinRenou martinRenou marked this pull request as draft June 30, 2021 12:59
@martinRenou
Copy link
Member Author

It's in a non-working state. I am opening this PR so that we can discuss it.

@jtpio
Copy link
Member

jtpio commented Jun 30, 2021

Thanks Martin for exploring this 👍

There is definitely room for improvement at the message passing level. For now mock-socket has been working ok, but maybe there is also a bit of refactor that can be done in @jupyterlab/services to make it easier for what we do in jupyterlite. Just an idea for now, but maybe that means making @jupyterlab/services or the ServiceManager more pluggable or make it possible to bypass the WebSocket completely.

@jtpio jtpio added the enhancement New feature or request label Jun 30, 2021
@jtpio
Copy link
Member

jtpio commented Jun 30, 2021

maybe there is also a bit of refactor that can be done in @jupyterlab/services to make it easier for what we do in jupyterlite. Just an idea for now, but maybe that means making @jupyterlab/services or the ServiceManager more pluggable or make it possible to bypass the WebSocket completely.

As a side note, we'll also probably want to have both in-browser and "normal" kernels supported at the same time. But that's something for another issue.

@bollwyvl
Copy link
Collaborator

This is a good step. There is a certain value in adhering as closely as possible to the WebSocket API, as some extensions will expect some of the plumbing to work exactly that way (even if they shouldn't). On that end, we should probably consider adding kernelspy to the demo site, and ensuring we generate content there, as losing the browser websocket playback, which just got good enough to use, is pretty crippling when you're building something and it goes wrong.

I'd love to eventually see a more broad embracing of native async generators on both the python and browser sides... i did a tiny bit of that over on #141. Definitely sounds like an upstream 2.0 (jp server) / 4.0 (lab) thing.

@jtpio
Copy link
Member

jtpio commented Jun 30, 2021

we should probably consider adding kernelspy to the demo site

Sounds good 👍 Opened https://github.com/jtpio/jupyterlite/issues/197 to track this.

@martinRenou
Copy link
Member Author

martinRenou commented Jul 5, 2021

After further investigation, I think it doesn't work because we also need to mock the server-mock and proxy-factory, which both use normalizeSendData (the function responsible for forcing data type to string).

That seems like a lot to mock in the mock socket...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request performance Gotta go fast
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants