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.
Hi, thanks for this library, it's pretty neat.
I intend to use a slightly changed version of it for a project, there are a few changes I made. I'd be happy to contribute it back if you like the changes.
The first thing I noticed is that the fact that the
Ctx
types are enums often makes the generated code inefficient, because the compiled functions contain pattern matches unless the compiler manages to optimize them out, which is pretty unpredictable. Protocols almost never require dynamically switching between Little-Endian and Big-Endian and so on, so it might be better to use individual types.In this PR I replace the enums with concrete types:
LittleEndian
BigEndian
Len
Pattern
PatternUntil
Delimiter
DelimiterUntil
I've also added a benchmark that reads and writes numeric types. On my machine this benchmark shows a 10-15% improvement on numeric code and much smaller code size.