Skip to content

Optimize Soroban WASM size & Refactor Heavy Libraries - #98

Merged
bakarezainab merged 3 commits into
LatterFixxx:mainfrom
Rampop01:fix/wasm-size-optimization
Aug 21, 2026
Merged

Optimize Soroban WASM size & Refactor Heavy Libraries#98
bakarezainab merged 3 commits into
LatterFixxx:mainfrom
Rampop01:fix/wasm-size-optimization

Conversation

@Rampop01

@Rampop01 Rampop01 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Description

This PR implements rigorous WASM size optimizations for the Soroban smart contract, addressing the binary bloat and porting constraints outlined in the issue. The optimizations significantly reduce the compiled WASM footprint (~50% reduction).

Changes Made

  • String Refactoring: Replaced all heavy String::from_str instantiations with lightweight Symbol::new across the contract to eliminate standard library string allocations.
  • Panic & Unwrap Optimization:
    • Removed #[derive(Debug)] on custom types and structs to avoid embedding heavy formatting implementations.
    • Removed string messages from panic!("...") and assert!("...") to prevent core::fmt logic from polluting the binary.
    • Substituted standard .unwrap() calls with .unwrap_optimized() (imported from soroban_sdk::unwrap::UnwrapOptimized) to eliminate panic branches during unwrapping.
  • Metadata Reduction: Stripped structural doc comments (///, //!) which the Soroban SDK normally compiles into the WASM custom sections (contractspecv0).
  • Compiler Profiles: Configured Cargo.toml for maximum size reduction (opt-level = "z", lto = true, codegen-units = 1, panic = "abort", strip = "symbols") and disabled overflow-checks.
  • Post-Compilation: Verified size optimization via wasm-opt -Oz.

Impact

  • Original Size: ~165KB
  • Optimized Size: ~84KB

Closes #86

@Rampop01

Copy link
Copy Markdown
Contributor Author

@bakarezainab all checks passed now, kindly review

@bakarezainab
bakarezainab merged commit 9de6261 into LatterFixxx:main Aug 21, 2026
1 check passed
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

Successfully merging this pull request may close these issues.

#086: Soroban WASM Size Reduction & AssemblyScript Porting Review

2 participants