-
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
Remove internal uses of withForeignPtr
#536
Conversation
My machine is giving me a very hard time, so I might not be able to continue work on this for a while. The timing is unfortunate. Maintainers, please feel free to push review suggestions to my branch as time is scarce. A few other thoughts:
|
Sorry, I’m AFK atm, will take a look tomorrow night. |
Yeah, I'd prefer to hide these helpers from users, |
The error messages from ghc-8.0 weren't red, so I didn't notice them. Silly stuff.
I was finally able to work on this again tonight. The diff is rather large, but the majority of it is a very mechanical translation from code that uses
|
to Data.ByteString.Internal.Type. The re-export-only compatibility module to replace it at Data.ByteString.Internal is intentionally deleted from this commit, to allow for a more reviewable diff.
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.
Thanks @clyring, insane amount of work!
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.
Thanks a lot, @clyring!
One minor wibble.
ping @sjakobi |
Apologies for the delay, @clyring! I intend to get back to this at the end of this week. BTW, has anyone investigated the perf impact already?
Otherwise I'll do that when I'm back. |
I tried measuring the effect on runtime via our benchmarks but the noise in my attempts was greater than the effect size. I also just tried running our entire testsuite with |
It has the same performance issues as does withForeignPtr.
I've verified that the improvement in runtime allocations is about 10% for the relevant GHC perf test. That test also allocates a bunch of list objects, so the improvement when looking at "only" bytestring stuff is probably a fair bit larger. (But I don't plan to investigate this any further.) PS: Thanks sjakobi for bringing the performance question back up. |
I've started comparing the benchmark results with this patch and GHC 9.2.4 vs. |
Here are some examples of persistent slowdowns (comparing
|
(Off topic: @clyring would you mind to drop me an email? I have a question to discuss, but cannot find your contacts) |
Not sure what else we can do here. If this branch is better than status quo, let’s merge as is? I’d like to push out 0.11.4.0 soon. |
I'd like to understand the Later today I will try to reproduce the 9.2.4 |
I was able to reproduce; it's rather terrible. |
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.
Sorry for the late response, guys! Indeed the regressions seem orthogonal to this patch.
Also, thanks a lot for all your work on bytestring
and taking on maintainer duties, @clyring! :)
* Avoid 'withForeignPtr' via 'createf' and variants * remove stupid/wrong temporary cpp * Move new utilities into D.B.Internal.Utils * Move unsafeWithForeignPtr shim into Utils * Fix imports for unsafeWithForeignPtr shim The error messages from ghc-8.0 weren't red, so I didn't notice them. Silly stuff. * Clean up potentially-sketchy unsafeWithForeignPtr uses * Revert documentation change to createAndTrim * Revert "Fix imports for unsafeWithForeignPtr shim" This reverts commit b6b4de6. Revert "Move unsafeWithForeignPtr shim into Utils" This reverts commit 6df394e. Revert "Move new utilities into D.B.Internal.Utils" This reverts commit 6462e4f. * Rename ForeignPtr helpers to use "Fp" suffix * [NONBUILDABLE] rename Data.ByteString.Internal to Data.ByteString.Internal.Type. The re-export-only compatibility module to replace it at Data.ByteString.Internal is intentionally deleted from this commit, to allow for a more reviewable diff. * Add compatibility stub "Data.ByteString.Internal" * Replace Data.ByteString.Internal.Type's description * Remove the use of withRawBuffer, too. It has the same performance issues as does withForeignPtr. Co-authored-by: Matthew Craven <[email protected]> # Conflicts: # Data/ByteString/Char8.hs # Data/ByteString/Internal.hs
As discussed at #535,
withForeignPtr
will be much slower in at least GHC-9.2.4 and GHC-9.4.1. So I made a quick pass at removing all internal uses of this function. To do this, I added variants of thecreate
family of functions whose "action" arguments takeForeignPtr Word8
instead ofPtr Word8
, allowing the caller to decide whether to usewithForeignPtr
orunsafeWithForeignPtr
. Then I used thoseForeignPtr
variants everywhere.I haven't yet had time to investigate whether this actually helps performance with 9.2.4 and obviously for a release I should need to do this against the 0.11 branch. But I thought I should push this for review now anyway.
Fixes #461.