-
Notifications
You must be signed in to change notification settings - Fork 272
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
WIP: add functions for converting Nats and Bytes with multiple word sizes #2278
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, something occurred to me. Tagging @pchiusano too.
If encoding is single values, like you encode one Nat
and then concatenate, that's going to lead to pretty fragmented Bytes
values, isn't it? The chunks will be extremely small, or if they aren't, it will be a bunch of expensive (due to copying) ByteString concatenation.
It's probably better to have something like Haskell's binary where you 'write' to an intermediate type and then finalize to get a Bytes
with reasonable chunk sizes.
return (b, (Unison.Util.Bytes.drop 2 bs)) | ||
|
||
encodeNat64be :: Word64 -> Bytes | ||
encodeNat64be n = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead of implementing this manually, it'd be better to use on of the binary encoding libraries we already depend on. E.G. we use bytes which has a bunch of endian-specific functions:
https://hackage.haskell.org/package/bytes-0.17.1/docs/Data-Bytes-Put.html
And can spit out a ByteString
afterward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dolio so I think we are doing much better now in this respect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that looks better. I just default to preferring something in a more widely used library if we're already using it. That way there's hopefully less question whether some fiddly detail is mistaken (because more people would have noticed by now).
So, the idea is that you can just call Basically, Also on that note, I wonder if going through That said, the implementation of the decoders could be much more efficient @stew to avoid going through |
I see. I guess flattening the bytes afterwards works fine. The stuff Stew wrote is also producing |
Ah yeah, good point. |
Great! Seems like this is pretty much there. What's going on with the CI though? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
Overview
What does this change accomplish and why? i.e. How does it change the user experience?
Fixes: #2277
Implementation notes
I added encode and decode functions to Bytes.hs and calling them as foreign functions
Interesting/controversial decisions
I would love for someone that knows what they are actually doing to check my encode functions on Bytes, and see if what I'm doing with a mutable block is an efficient / correct way of creating Bytes
Test coverage
TODO