byte icon indicating copy to clipboard operation
byte copied to clipboard

Trait based contexts

Open jac3km4 opened this issue 2 years ago • 0 comments

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.

jac3km4 avatar Feb 10 '24 18:02 jac3km4