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

Support for numpy in Javascript through another serilization like MessagePack #10

Open
VigneshVSV opened this issue Jul 19, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@VigneshVSV
Copy link
Owner

VigneshVSV commented Jul 19, 2024

HTTP can support MessagePack headers for content type.

Numpy arrays are serialized as fast as python's pickle by MessagePack format msgspec.msgpack . However, to unpack it on the javascript side, a suitable deserialization is necessary. MessagePack is also safer than pickle, so currently pickle is not support for HTTP access, but message pack support would be great.

The expected server side code is as follows:

class MyThing(Thing)
    
    _numpy_event = Event() 
    
    @action()
    def numpy_gen(self) -> memoryview:
        return memoryview(self._large_numpy_array)
       
    def event_pub(self) -> None:
         while True:
             self._numpy_event.push(memoryview(self._large_numpy_array)
             time.sleep(1)

if __name__ == '___main__':
     MyThing(instance_name='my-thing', serializer='msgpack').run_with_http_server()

However, a javascript library which can read this memoryview data is not known.

Any suggestions are welcome.

+----------------------------------------------------------------------------------------------------------------------+
| serializer | spectrum | spectrum 1e4 double entries | spectrum 1e5 entries | spectrum 1e6 entries |
+=====================================================================+
| JSONSerializer | 0.05121 | 0.61983 | 6.29486 | 65.279 |
+----------------------------------------------------------------------------------------------------------------------+
| PickleSerializer | 0.01586 | 0.01927 | 0.26054 | 8.31536 |
+----------------------------------------------------------------------------------------------------------------------+
| MsgpackSerializer | 0.01237 | 0.09472 | 1.13373 | 15.2071 |
+----------------------------------------------------------------------------------------------------------------------+

@VigneshVSV VigneshVSV added enhancement New feature or request help wanted Extra attention is needed and removed help wanted Extra attention is needed labels Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant