Avoid copies when passing binary parameters#22
Closed
robx wants to merge 5 commits into
Closed
Conversation
phadej
requested changes
Jul 3, 2022
Collaborator
phadej
left a comment
There was a problem hiding this comment.
This PR does multiple things at once. Please split.
There were two identical copies each of the parameter mangling code.
Instead of building a list of 'Int' in the fold, and then mapping 'toEnum' over it, build a list of 'CInt' directly.
We encode various arrays of the same length through 'withArray'. Each of these computes the length, so we might as well take the length from one of these.
Contributor
Author
|
I've split out the first commit in #23, will file follow-up PRs if/as that one gets merged. |
Contributor
Author
|
Apologies for the re-review request, meant to request review for #23. |
Contributor
Author
Did you see #23? Is that what you had in mind? |
Collaborator
Contributor
Author
|
Sorry, that's because I was repurposing the branch to file a PR against a fork of this repo. Closing. |
Collaborator
|
fork? interesting... |
Contributor
Author
|
There's no desire to fork, I just want to move forward with this in PostgREST in some way, and the best choice seems to be to build against a (hopefully temporary) fork. Some discussion over here if you're interested: PostgREST/postgrest#2422 |
This was referenced Nov 4, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, the library copies every input parameter when passing it to libpq via
Data.ByteString.useAsCString. This PR avoids those copies for the case of binary parameters, by usingData.ByteString.Unsafe.unsafeUseAsCString.I claim that this is safe because:
ByteStringuses pinned memoryThere are a few preparatory commits to factor out duplicate code to
withParams, and to avoid a bit of unnecessary work there.Context is PostgREST/postgrest#2261. We see significant decrease of memory use with this change: PostgREST/postgrest#2349