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

Base64 Optimization #237

Merged
merged 4 commits into from
Jan 9, 2024
Merged

Conversation

neotheprogramist
Copy link
Contributor

  • optimization of previous base64 encoding algorithm to use less gas
  • direct base64 encoding from felt252

@0xLucqs
Copy link
Collaborator

0xLucqs commented Jan 5, 2024

can you add numbers here plz. At least gas and ideally steps/builtins

@piniom
Copy link
Contributor

piniom commented Jan 5, 2024

@LucasLvy

  1. The change to the encoding of Array. Testing on an array of 32 bytes (most use-cases) the old implementation uses 7317558 gas while the new one uses only 804588. It is more than 9 times less. Both implementations have linear complexity so changing the length of the data doesn't affect the relative improvement as tested.
  2. Encoding of felt252. The use-case that led to the development of this part was that we needed to encode the transaction hash to base64. Directly encoding the hash (felt252) instead of writing it as an Array of length 32 in big endian and then encoding leads to a 2.2x improvement (or 11.6x when using the old array encoding function).

Copy link
Collaborator

@0xLucqs 0xLucqs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either say why the unwraps are safe or remove them and switch to results plz

src/encoding/src/base64.cairo Outdated Show resolved Hide resolved
src/encoding/src/base64.cairo Outdated Show resolved Hide resolved
src/encoding/src/base64.cairo Outdated Show resolved Hide resolved
src/encoding/src/base64.cairo Outdated Show resolved Hide resolved
src/encoding/src/base64.cairo Show resolved Hide resolved
src/encoding/src/base64.cairo Show resolved Hide resolved
src/encoding/src/base64.cairo Outdated Show resolved Hide resolved
src/encoding/src/base64.cairo Show resolved Hide resolved
src/encoding/src/tests/base64_felt_test.cairo Outdated Show resolved Hide resolved
src/encoding/src/tests/base64_felt_test.cairo Show resolved Hide resolved
@0xLucqs 0xLucqs merged commit 085f17c into keep-starknet-strange:main Jan 9, 2024
3 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants