-
Notifications
You must be signed in to change notification settings - Fork 141
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
Create strict bytestrings from FixedPrim with zero copy #666
Comments
If you decide on a solution, I can implement and and submit it. |
|
Thanks for digging into the the performance of the the particular code. After looking at the What do you think about doing both 2 and 3? A value of |
My main complaint with solution 2 is that I don't think it solves a real problem. If you have need of it, feel free to import |
This makes sense. I'm going to use the internal modules. It would be nice to remove the disclaimer, as you suggested. It gives a different impression about stability than you described. Would you be open to a PR that implements 3? |
Fire away! |
To turn a FixedPrim into a strict ByteString, with the current public interface I can do something like this:
Once
primFixed :: FixedPrim a -> a -> Builder
converts a value toBuilder
, there are only utilities to convert it into a lazy bytestring.One alternative is to use
runF :: FixedPrim a -> a -> Ptr Word8 -> IO ()
together withcreate :: create :: Int -> (Ptr Word8 -> IO ()) -> IO ByteString
but that relies on two internal modulesData.ByteString.Builder.Prim.Internal
andData.ByteString.Internal
.I propose three solutions:
Builder -> Ptr Word8 -> IO ()
runF :: FixedPrim a -> a -> Ptr Word8 -> IO ()
from the public moduleData.ByteString.Builder.Prim
.primToByteString :: FixedPrim a -> a -> ByteString
that creates a strict bytestring right away.For both 1 and 2 the code would rely on the
create
from the semi-public moduleData.ByteString.Internal
.For the context, the benchmarking in haskell-hvr/uuid#80 shows that the overhead of copy from
toStrict
slows down the conversion by 40% (28ns vs 20ns).The text was updated successfully, but these errors were encountered: