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

Optimize performance of bech32 encoding implementation #74

Closed
maciejka opened this issue May 22, 2024 · 23 comments
Closed

Optimize performance of bech32 encoding implementation #74

maciejka opened this issue May 22, 2024 · 23 comments
Labels

Comments

@maciejka
Copy link
Collaborator

maciejka commented May 22, 2024

OD Hack

This issue is part of ODHack 4.0:

Task

Here is a bech32 encoding implementation in Cairo:

pub fn encode(hrp: @ByteArray, data: @ByteArray, limit: usize) -> ByteArray {

Your task is to optimize it.

You should provide measurements before and after the optimization.

NOTE: This task is about providing objective code performance optimizations. In case you want to provide a pr, please make sure it contains a description of what and how you want to optimize and measurements before and after optimization. In case you have several optimization ideas please submit them as separate prs.

References

Communication

https://t.me/JoyboyStarknet/949

May the Joy be with you!

@maciejka maciejka added help wanted Extra attention is needed OD Hack medium labels May 22, 2024
@kateberryd
Copy link
Contributor

kateberryd commented May 22, 2024

@maciejka I would love to work on this

@juandiegocv27
Copy link

juandiegocv27 commented May 22, 2024

Hi, @maciejka I would love to contribute to this task: starting to May 23, 2024, to Completion Date: June 1, 2024, I'm Juan Diego Carballo and I'm a full-stack developer with a software engineer degree, already contributed to other projects and creating an on-chain game. I have experience with Cairo and blockchain development, including implementing and optimizing encoding algorithms. Already follow Joyboy on twitter and joined the Telegram.

@saimeunt
Copy link

Hi @maciejka, I recently participated in a gas golfing competition hosted by NodeGuardians and had a lot of fun optimizing contracts in Solidity.

I'm familiar with Cairo and would love to try optimizing the current reference implementation to save some Cairo steps.
I will try to optimize the best I can without sacrificing on the readability of the code, I will study other implementations of Bech32 to search for interesting approaches.

@maciejka
Copy link
Collaborator Author

Hey ODHackers! So many volunteers! Please send me your ideas for optimizations in pm on tg: @aundumla. I will assign the task based on quality of your proposals.

@juandiegocv27
Copy link

@maciejka in which channel of the telegram?

@maciejka
Copy link
Collaborator Author

maciejka commented May 23, 2024

More than one can work on this issue if the ideas for optimizations are different.

@maciejka maciejka changed the title Optimize bech32 encoding implementation Optimize performance of bech32 encoding implementation May 28, 2024
@juandiegocv27 juandiegocv27 removed their assignment May 29, 2024
@juandiegocv27
Copy link

@maciejka sorry, give the issue to someone else

@maciejka maciejka removed the OD Hack label Jun 4, 2024
@mathstickz
Copy link

i would love to take part in the success of this issue @maciejka

@maciejka
Copy link
Collaborator Author

maciejka commented Jul 4, 2024

i would love to take part in the success of this issue @maciejka

Please provide a pr.

@nicosanc
Copy link

nicosanc commented Jul 4, 2024

Out of curiosity (since I am still a beginner), what kind of optimizations are you typically looking for when developing in Cairo? Is it things like bit packing or more complex optimization concepts?

@maciejka
Copy link
Collaborator Author

maciejka commented Jul 4, 2024 via email

@quentin-abei
Copy link

Hello, is this still an issue to tackle ? I would want to work on it

@maciejka
Copy link
Collaborator Author

maciejka commented Jul 22, 2024 via email

@quentin-abei
Copy link

quentin-abei commented Jul 24, 2024

Are there any available tool to measure cairo code optimization that one could use ?

@maciejka
Copy link
Collaborator Author

Are there any available tool to measure cairo code optimization that one could use ?

Check: https://foundry-rs.github.io/starknet-foundry/snforge-advanced-features/profiling.html

@remybar
Copy link

remybar commented Aug 6, 2024

Hi @maciejka !

I made some optimization on the bech32 encode function and if I compare gas consumption, I get an improvement of around 60%.
I did a small scarb project with your reference implementation and the optimized one in this repo: https://github.com/remybar/bech32-optimization.

I will continue in the following days if I find some new ideas ;-)

But I would appreciate any feedback just to be sure it is what you expect.

Note that it uses Cairo 2.7.0.

@maciejka
Copy link
Collaborator Author

maciejka commented Aug 6, 2024

It is super cool! Cairo 2.7.0 is the right choice.
It will be easier for me to see the differences and ask questions if you would provide a pr.

@Judacris32
Copy link

@maciejka can i be assigned to this issue

Copy link

onlydustapp bot commented Aug 14, 2024

Hey @Judacris32!
Thanks for showing interest.
We've created an application for you to contribute to Joyboy Community.
Go check it out on OnlyDust!

@remybar
Copy link

remybar commented Aug 16, 2024

It is super cool! Cairo 2.7.0 is the right choice. It will be easier for me to see the differences and ask questions if you would provide a pr.

Hi @maciejka !
Sorry, I just discover your answer, I didn't receive any notification 😅

I'm preparing a PR to bump joyboy to Cairo 2.7.0 but it requires an update from snfoundry. Then I will quickly prepare a PR for this optimization ;-)

Copy link

onlydustapp bot commented Aug 16, 2024

Hey @remybar!
Thanks for showing interest.
We've created an application for you to contribute to Joyboy Community.
Go check it out on OnlyDust!

@remybar
Copy link

remybar commented Aug 18, 2024

It is super cool! Cairo 2.7.0 is the right choice. It will be easier for me to see the differences and ask questions if you would provide a pr.

I've just created a new PR: #297

Note that this PR is based on my other PR to bump to Cairo 2.7.0 so just look at the bech32.cairo file to see the modifications related to the optimization of bech32.

Don't hesitate if you have any questions ;-) And if you want to see the gain in term of gas, you should have a look at the small project I mentioned before (https://github.com/remybar/bech32-optimization).

@maciejka
Copy link
Collaborator Author

maciejka commented Sep 4, 2024

Since this project is paused I am closing this issue in order not to confuse peaople. @remybar thanks for your work.

@maciejka maciejka closed this as completed Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants