joyboy
joyboy copied to clipboard
Feat improve bech32 perf
Related to https://github.com/keep-starknet-strange/joyboy/issues/74.
This PR uses Cairo 2.7.0
so it depends on the PR https://github.com/keep-starknet-strange/joyboy/pull/296 (which is blocked until snfoundry
has been updated to work with Cairo 2.7.0
).
Proposed optimizations:
- use a const fixed-size array for alphabet,
- direct conversion from ByteArray to 5-bits chunks,
- use
for in
loop inencode
, - avoid creating temporary arrays,
- hardcode generator loop in
polymod
, - avoid using
shr
inpolymod
, - call
polymod
directly, without intermediate arrays.
Note that all modifications have been done in bech32.cairo
. The other modifications come from the PR https://github.com/keep-starknet-strange/joyboy/pull/296.