You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consideration for decode array to tuple by default option. #30
msgpack-pythonhas an option: use_list=False to its unpacker to allow for decoding to tuple 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 then list?
changed the title [-]Cosideration for decode array to `tuple` by default option.[/-][+]Consideration for decode array to `tuple` by default option.[/+]on Jun 11, 2021
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. (1, 2, 3)) are "faster" since they're built only once by the compiler. Both lists and tuples have similar representations in cpython, and take equivalent time to construct dynamically. A quick benchmark using msgspec:
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]: %timeitdec_list.decode(buf)
12.9µs ± 20.8nsperloop (mean ± std. dev. of7runs, 100000loopseach)
In [10]: %timeitdec_tuple.decode(buf)
12.9µs ± 17.3nsperloop (mean ± std. dev. of7runs, 100000loopseach)
I'm not enthused about adding a use_list-like option. Lists are the natural default type for MessagePack's array type. If you want to use a different type for arrays then you likely have a schema you're following and I'd direct you to use msgspec's support for typed serialization.
Activity
[-]Cosideration for decode array to `tuple` by default option.[/-][+]Consideration for decode array to `tuple` by default option.[/+]Add streaming decode support for `msgspec`
Add streaming decode support for `msgspec`
jcrist commentedon Jun 27, 2021
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.
(1, 2, 3)) are "faster" since they're built only once by the compiler. Both lists and tuples have similar representations in cpython, and take equivalent time to construct dynamically. A quick benchmark using msgspec:I'm not enthused about adding a
use_list-like option. Lists are the natural default type for MessagePack's array type. If you want to use a different type for arrays then you likely have a schema you're following and I'd direct you to use msgspec's support for typed serialization.goodboy commentedon Jun 28, 2021
@jcrist learn something new every time I report something here 🏄🏼
You'd think i would have double checked the
tuplecreate speed claim 🙄Is it possible the
.encode()step here is faster though?Honestly, keeping it as is works for me as simpler is always better imo.
I can close this is no one else is going to have quiffs.
Yeah i think focusing on a struct schema is really the right way to designing things anyway 👍🏼
jcrist commentedon Jun 28, 2021
No problem, happy to help.
Both store their data as an array of
PyObject*, so I wouldn't expect a difference. Easy enough to benchmark though:Closing!
Add streaming decode support for `msgspec`
Add streaming decode support for `msgspec`
Add streaming decode support for `msgspec`
Convert actor UIDs to hashable tuples
Convert actor UIDs to hashable tuples
Add streaming decode support for `msgspec`
Convert actor UIDs to hashable tuples
Add streaming decode support for `msgspec`
Convert actor UIDs to hashable tuples
Add streaming decode support for `msgspec`
Convert actor UIDs to hashable tuples
Add streaming decode support for `msgspec`
Convert actor UIDs to hashable tuples
Add streaming decode support for `msgspec`
Convert actor UIDs to hashable tuples
Add streaming decode support for `msgspec`
Convert actor UIDs to hashable tuples
Fix `Meta(pattern=..)` memory leak / corruption (msgspec#1256)