Skip to content

WIP: Use inline bitwise operations for encoding

Hey there Seb! I was looking at your project after today's presentation, and thought it could probably use some speed up.

Since the conversion octet<->nonet is part of the "standard", the dynamic bitfield classes and manipulation are not really needed (that creates a lot of temporary Field objects). Using inline bitwise operations instead can speed things up quite a bit. Of course the cost is to have a little of duplicated-looking code, although I'd argue it's actually easier to understand what's being done.

Anyway, I was just trying this out for encoding only first, from a quick test it's twice as fast to encode a single char (e.g. encode('a')), but nearly 10x faster when encoding longer content like encode('foobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobar') and I expect the speed difference compounds with really large input.

I haven't tried to do the same for decoding (time for bed for me!) but since I had the encoding done with such a significant speedup, I thought I'd send that to you first anyway for your perusal.

Disclaimer: I haven't done much testing yet, so it's possible it's not strict equivalence.

Cheers!

Merge request reports