Skip to content

Specialized row decoders per type and pinned byte arrays - #49

Draft
mzabani wants to merge 35 commits into
masterfrom
pinned-byte-arrays
Draft

Specialized row decoders per type and pinned byte arrays#49
mzabani wants to merge 35 commits into
masterfrom
pinned-byte-arrays

Conversation

@mzabani

@mzabani mzabani commented Aug 24, 2026

Copy link
Copy Markdown
Owner

This needs to be rebased and explained.

This has technically breaking API changes (but most users shouldn't be affected and it's easy to adapt to the changes) and still needs a lot of thinking before being merged.

Before merging:

  • Double-check Generically derived FromPgRow instances don't blow up in size
  • Does it make sense to even have a FieldDecoder type? It's much nicer for implementers than implementing RowDecoder, but maybe we can provide functions to facilitate the latter.
  • Look at the instance FromPgField MyEnum's definition, and see that users have no way of using fail with rawBytesFieldDecoder. Maybe something to keep in mind in any form of API changes.
  • Check the diff in the tests project, benchmarks and hpgsql-simple-compat, to understand the extent of changes users of hpgsql will have to make (particularly if we break API compatibility)

mzabani added 30 commits August 12, 2026 14:41
This improves our "Record Stream" benchmarks by ~8.2%, even if total
memory allocated goes up a bit.
It's only used to fetch field values, and values with length exactly 0
are extremely rare
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.
With this, I am able to write specialised `FromPgField (Maybe a)`
instances that can inline more aggressively.

The gotcha is
Let's see if this is better than the OVERLAPPING instances
This is the prize I was looking for.

Now the row decoders are built with the NULL handling parts a lot more
inlined, which even means in a fully inlined row decoder we no longer
box into a `Maybe a` to then case match on it and fail on `Nothing`,
when the target record has a field typed as `a` (not a Maybe).
Types like `Scientific` are not being decoded optimally otherwise, and
they can do better than in the current state
Becase we don't have a FieldInfo when decoding NULL anymore. Not sure
what we can do.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant