Specialized row decoders per type - #48
Draft
mzabani wants to merge 10 commits into
Draft
Conversation
We're beginning to converge to row decoders not being inlined by default, but their implementations/bodies being as inlined as possible, which feels reasonable. It remains to be seen if we can add a super-inlined version of row decoders for users to choose from if they wish, and what the effects are.
The boundary here is very nice: users that want to avoid too much code bloat can use the non-inlined decoders, and those that want to max out performance can use the inlined decoders.
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.
Part 3 of perf optimizations. This has API changes (most likely not breaking) and still needs a lot of thinking before being merged.
The main idea here is to spread usage of our CPS Parser all the way down to decoders by adding RowDecoder-returning methods to the
FromPgFieldtypeclass.Together with the previous PR (
ByteStringIdxpassing), we can avoid creating instances ofByteStringwe currently need due tofieldDecoderrequiring it (fieldValueDecoder :: FieldInfo -> Maybe ByteString -> Either String a).If we're willing to break backwards compatibility a bit, we could try to change that to
fieldValueDecoder :: FieldInfo -> PgValue -> Either String aand makePgValuesomething likeSqlNull | NotNull !ByteString !ByteStringIdx !ByteStringIdx: a slice of the original buffer/bytestring, which guarantees no copies even when using this method. Having this custom type would be breaking now, but if we hide its internals it will give us room to experiment changing the representation in the future (e.g. I'm seriously considering switching from ByteString to ShortByteString).However, this still wouldn't allow for some niche optimizations like our small-value decoding
decodePgFieldWithAtMost4Bytes, because that reads 8 bytes and needs to have the parser position/ByteStringIdx pointing to the field length, not the field's value itself.There is also a matter of optimizing
Maybe ainstances, which is tricky. Currently OVERLAPPING instances have worked for base types, but we would want something that extends naturally to user defined types without asking them to create OVERLAPPING instances themselves (not to mention they'd need "awkward" decoding functions or access to our CPS Parser, which is still internal).It's best to solve the
Maybe aproblem first, because that's a problem regardless of the rest.Before merging:
SqlNull | NotNull !ShortByteStringexperiment again after all these improvements, where it might finally make things better, not worse.FromPgField ahas a methodRowDecoder (Maybe a)instead ofRowDecoder a.FieldDecodertype? That makes field composition benefit from it.instance FromPgField MyEnum's definition, and see that users have no way of usingfailwithrawBytesFieldDecoder. Maybe something to keep in mind in any form of API changes.