nikita-volkov / ptr-poker

Pointer poking action construction and composition toolkit
http://hackage.haskell.org/package/ptr-poker
MIT License
8 stars 5 forks source link

ByteString: use unsafeWithForeignPtr if available #16

Closed raehik closed 1 year ago

raehik commented 1 year ago

Mentioned in #15. Note included in bytestring compat module copied here:

GHC 9.0 made withForeignPtr sound at the cost of performance. If you want to use the faster unsafe implementation, it's now at unsafeWithForeignPtr, and GHC asks you to promise that your continuation does not diverge. All we do here is memcpy bytestrings, so we gladly pinky swear. For more detail, see Ben Gamari's post: https://www.haskell.org/ghc/blog/20210607-the-keepAlive-story.html

Note that fumieval's mason uses unsafeWithForeignPtr in the same way also to copy bytestrings.

raehik commented 1 year ago

@nikita-volkov This seems to be the culprit of some of the performance improvements I was seeing in my library, specifically for serializing lots of small-ish bytestrings.

raehik commented 1 year ago

Note that there are no benchmarks for bytestring serialization currently.