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

Evaluate if Symbol::new should try to optimize or always create symbol using host fn #1298

Open
leighmcculloch opened this issue Jul 16, 2024 · 0 comments

Comments

@leighmcculloch
Copy link
Member

leighmcculloch commented Jul 16, 2024

Today the Symbol::new function in the SDK/Env converts a &str to a Symbol by checking if the length of the str is small enough to be encoded as a SymbolVal, and if so it takes that route, otherwise it calls a host function copying the str to the host and getting back a SymbolObject.

The current approach was implemented before we knew much about how costs and fees would work on Soroban, and makes some tradeoffs that may not be the right tradeoffs anymore. We know more today than we did a year or more ago about costs and fees and should re-evaluate if the existing behavior and tradeoffs are appropriate.

Todays approach where Symbol::new optimistically returns a SymbolVal or SymbolObject optimizes for less host function calls, but str to SymbolVal conversion costs ~200 bytes of WASM instructions.

Another approach where Symbol::new always returns a SymbolObject would optimize for smaller contracts and result in only an additional ~58 bytes of WASM instructions but result in an additional host function call for every conversion.

More analysis is required when priorities permits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@leighmcculloch and others