-
Notifications
You must be signed in to change notification settings - Fork 82
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
Consideration for decode array to tuple
by default option.
#30
Comments
tuple
by default option.tuple
by default option.
Add a `tractor._ipc.MsgspecStream` type which can be swapped in for `msgspec` serialization transparently. A small msg-length-prefix framing is implemented as part of the type and we use `tricycle.BufferedReceieveStream` to handle buffering logic for the underlying transport. Notes: - had to force cast a few more list -> tuple spots due to no native `tuple`decode-by-default in `msgspec`: jcrist/msgspec#30 - the framing can be understood by this protobuf walkthrough: https://eli.thegreenplace.net/2011/08/02/length-prefix-framing-for-protocol-buffers - `tricycle` becomes a new dependency
Add a `tractor._ipc.MsgspecStream` type which can be swapped in for `msgspec` serialization transparently. A small msg-length-prefix framing is implemented as part of the type and we use `tricycle.BufferedReceieveStream` to handle buffering logic for the underlying transport. Notes: - had to force cast a few more list -> tuple spots due to no native `tuple`decode-by-default in `msgspec`: jcrist/msgspec#30 - the framing can be understood by this protobuf walkthrough: https://eli.thegreenplace.net/2011/08/02/length-prefix-framing-for-protocol-buffers - `tricycle` becomes a new dependency
Apologies for the delay here. Tuples aren't more performant than lists to create or use. If you read through the answers in the link above, you'd see that only constant tuples (e.g. In [5]: data = list(range(1000))
In [6]: dec_list = msgspec.Decoder(list)
In [7]: dec_tuple = msgspec.Decoder(tuple)
In [8]: buf = msgspec.encode(data)
In [9]: %timeit dec_list.decode(buf)
12.9 µs ± 20.8 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
In [10]: %timeit dec_tuple.decode(buf)
12.9 µs ± 17.3 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) I'm not enthused about adding a |
@jcrist learn something new every time I report something here 🏄🏼 You'd think i would have double checked the Honestly, keeping it as is works for me as simpler is always better imo.
Yeah i think focusing on a struct schema is really the right way to designing things anyway 👍🏼 |
No problem, happy to help.
Both store their data as an array of In [1]: import msgspec
In [2]: enc = msgspec.Encoder()
In [3]: msg_tuple = tuple(range(1000))
In [4]: msg_list = list(range(1000))
In [5]: %timeit enc.encode(msg_tuple)
10.3 µs ± 26.3 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
In [6]: %timeit enc.encode(msg_list)
10.3 µs ± 20.6 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
Closing! |
Add a `tractor._ipc.MsgspecStream` type which can be swapped in for `msgspec` serialization transparently. A small msg-length-prefix framing is implemented as part of the type and we use `tricycle.BufferedReceieveStream` to handle buffering logic for the underlying transport. Notes: - had to force cast a few more list -> tuple spots due to no native `tuple`decode-by-default in `msgspec`: jcrist/msgspec#30 - the framing can be understood by this protobuf walkthrough: https://eli.thegreenplace.net/2011/08/02/length-prefix-framing-for-protocol-buffers - `tricycle` becomes a new dependency
Add a `tractor._ipc.MsgspecStream` type which can be swapped in for `msgspec` serialization transparently. A small msg-length-prefix framing is implemented as part of the type and we use `tricycle.BufferedReceieveStream` to handle buffering logic for the underlying transport. Notes: - had to force cast a few more list -> tuple spots due to no native `tuple`decode-by-default in `msgspec`: jcrist/msgspec#30 - the framing can be understood by this protobuf walkthrough: https://eli.thegreenplace.net/2011/08/02/length-prefix-framing-for-protocol-buffers - `tricycle` becomes a new dependency
Add a `tractor._ipc.MsgspecStream` type which can be swapped in for `msgspec` serialization transparently. A small msg-length-prefix framing is implemented as part of the type and we use `tricycle.BufferedReceieveStream` to handle buffering logic for the underlying transport. Notes: - had to force cast a few more list -> tuple spots due to no native `tuple`decode-by-default in `msgspec`: jcrist/msgspec#30 - the framing can be understood by this protobuf walkthrough: https://eli.thegreenplace.net/2011/08/02/length-prefix-framing-for-protocol-buffers - `tricycle` becomes a new dependency
`msgspec` sends python lists over the wire (jcrist/msgspec#30) which is fine and dandy but we use them as lookup keys so we need to be sure we tuple-cast first.
`msgspec` sends python lists over the wire (jcrist/msgspec#30) which is fine and dandy but we use them as lookup keys so we need to be sure we tuple-cast first.
Add a `tractor._ipc.MsgspecStream` type which can be swapped in for `msgspec` serialization transparently. A small msg-length-prefix framing is implemented as part of the type and we use `tricycle.BufferedReceieveStream` to handle buffering logic for the underlying transport. Notes: - had to force cast a few more list -> tuple spots due to no native `tuple`decode-by-default in `msgspec`: jcrist/msgspec#30 - the framing can be understood by this protobuf walkthrough: https://eli.thegreenplace.net/2011/08/02/length-prefix-framing-for-protocol-buffers - `tricycle` becomes a new dependency
`msgspec` sends python lists over the wire (jcrist/msgspec#30) which is fine and dandy but we use them as lookup keys so we need to be sure we tuple-cast first.
Add a `tractor._ipc.MsgspecStream` type which can be swapped in for `msgspec` serialization transparently. A small msg-length-prefix framing is implemented as part of the type and we use `tricycle.BufferedReceieveStream` to handle buffering logic for the underlying transport. Notes: - had to force cast a few more list -> tuple spots due to no native `tuple`decode-by-default in `msgspec`: jcrist/msgspec#30 - the framing can be understood by this protobuf walkthrough: https://eli.thegreenplace.net/2011/08/02/length-prefix-framing-for-protocol-buffers - `tricycle` becomes a new dependency
`msgspec` sends python lists over the wire (jcrist/msgspec#30) which is fine and dandy but we use them as lookup keys so we need to be sure we tuple-cast first.
Add a `tractor._ipc.MsgspecStream` type which can be swapped in for `msgspec` serialization transparently. A small msg-length-prefix framing is implemented as part of the type and we use `tricycle.BufferedReceieveStream` to handle buffering logic for the underlying transport. Notes: - had to force cast a few more list -> tuple spots due to no native `tuple`decode-by-default in `msgspec`: jcrist/msgspec#30 - the framing can be understood by this protobuf walkthrough: https://eli.thegreenplace.net/2011/08/02/length-prefix-framing-for-protocol-buffers - `tricycle` becomes a new dependency
`msgspec` sends python lists over the wire (jcrist/msgspec#30) which is fine and dandy but we use them as lookup keys so we need to be sure we tuple-cast first.
Add a `tractor._ipc.MsgspecStream` type which can be swapped in for `msgspec` serialization transparently. A small msg-length-prefix framing is implemented as part of the type and we use `tricycle.BufferedReceieveStream` to handle buffering logic for the underlying transport. Notes: - had to force cast a few more list -> tuple spots due to no native `tuple`decode-by-default in `msgspec`: jcrist/msgspec#30 - the framing can be understood by this protobuf walkthrough: https://eli.thegreenplace.net/2011/08/02/length-prefix-framing-for-protocol-buffers - `tricycle` becomes a new dependency
`msgspec` sends python lists over the wire (jcrist/msgspec#30) which is fine and dandy but we use them as lookup keys so we need to be sure we tuple-cast first.
Add a `tractor._ipc.MsgspecStream` type which can be swapped in for `msgspec` serialization transparently. A small msg-length-prefix framing is implemented as part of the type and we use `tricycle.BufferedReceieveStream` to handle buffering logic for the underlying transport. Notes: - had to force cast a few more list -> tuple spots due to no native `tuple`decode-by-default in `msgspec`: jcrist/msgspec#30 - the framing can be understood by this protobuf walkthrough: https://eli.thegreenplace.net/2011/08/02/length-prefix-framing-for-protocol-buffers - `tricycle` becomes a new dependency
`msgspec` sends python lists over the wire (jcrist/msgspec#30) which is fine and dandy but we use them as lookup keys so we need to be sure we tuple-cast first.
Add a `tractor._ipc.MsgspecStream` type which can be swapped in for `msgspec` serialization transparently. A small msg-length-prefix framing is implemented as part of the type and we use `tricycle.BufferedReceieveStream` to handle buffering logic for the underlying transport. Notes: - had to force cast a few more list -> tuple spots due to no native `tuple`decode-by-default in `msgspec`: jcrist/msgspec#30 - the framing can be understood by this protobuf walkthrough: https://eli.thegreenplace.net/2011/08/02/length-prefix-framing-for-protocol-buffers - `tricycle` becomes a new dependency
`msgspec` sends python lists over the wire (jcrist/msgspec#30) which is fine and dandy but we use them as lookup keys so we need to be sure we tuple-cast first.
msgpack-python
has an option:use_list=False
to its unpacker to allow for decoding totuple
by default.I noticed in the docs that tuples are only used for array types when used as hashable keys.
Is there a reason there isn't a way to either offer the
tuple
-as-default by a manual flag or, just by default decode to the same type considering they're ostensibly more performant in python thenlist
?The text was updated successfully, but these errors were encountered: