Skip to content
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

1.4.5: Add reverse encoders for packed repeated fields. #108

Merged
merged 29 commits into from
Mar 18, 2025

Conversation

j6carey
Copy link
Collaborator

@j6carey j6carey commented Aug 8, 2024

When encoding from a Data.Vector.Vector this library would already encode from right to left in order to avoid saving all but the final element to the stack. The relevant encoders would also exploit the fact that vectors have known element counts in order to consolidate size checks and associated reallocations when encoding packed fields with fixed-width elements.

This change adds new encoders that generalize those two optimizations to other types of container such as Data.Sequence.Seq. When a container does not support right-to-left iteration and/or length prediction (for example, a standard list), these new encoders still support them as efficiently as is practical, given those restrictions.

Also added: bytesIfNonempty, etaMessageBuilder, repeatedMessageBuilder, unsafeFromByteString, unsafeFromShortByteString.

j6carey added 26 commits August 8, 2024 10:49
Like the Vector encoders but unlike the forward-order
Foldable encoders they avoid the need to save elements
to the stack before encoding them, instead immediately
encoding the final element as the first step.  However,
the new encoders lack the special optimizations around
size checks that are possible for the Vector encoders,
which have advance knowledge of the number of elements.

This change also avoids compiler warnings in benchmark code.
They are no more unsafe than unsafeFromLazyByteString.
@j6carey j6carey requested a review from riz0id March 17, 2025 15:03
@j6carey j6carey changed the title 1.4.4: Add reverse encoders for packed repeated fields. 1.4.5: Add reverse encoders for packed repeated fields. Mar 18, 2025
@j6carey j6carey merged commit d4376fb into master Mar 18, 2025
19 checks passed
@j6carey j6carey deleted the jcarey-reverse-packed-encoders branch March 18, 2025 19:26
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.

2 participants