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

Trait based contexts #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

jac3km4
Copy link

@jac3km4 jac3km4 commented Feb 10, 2024

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.

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.

None yet

1 participant