Skip to content

perf: replace swap_path Vec<Address> with fixed-size SwapPath type#313

Open
Tomoya0k wants to merge 2 commits into
SO4-Markets:mainfrom
Tomoya0k:perf/swap-path-clean
Open

perf: replace swap_path Vec<Address> with fixed-size SwapPath type#313
Tomoya0k wants to merge 2 commits into
SO4-Markets:mainfrom
Tomoya0k:perf/swap-path-clean

Conversation

@Tomoya0k

Copy link
Copy Markdown

Closes #300

Summary

  • Benchmarked three representations and adopted std::vec::Vec<Address> (fastest at 16,234 CPU instructions vs 20,106 for soroban_sdk::Vec)
  • Defined SwapPath contract type with MAX_SWAP_PATH_LENGTH = 5 in libs/types
  • Enforced path length limit at order creation time
  • All existing swap tests pass including boundary and two-hop cases

Benchmark results

Representation CPU Mem
std::vec::Vec 16,234 5,811
soroban_sdk::Vec 20,106 5,947
[Option; 5] 16,686 5,811

Full write-up in docs/swap_path_optimization.md.

Tomoya0k and others added 2 commits June 24, 2026 01:28
- Define SwapPath contract type and MAX_SWAP_PATH_LENGTH = 5 in libs/types
- std::Vec was fastest (16,234 CPU) vs soroban_sdk::Vec (20,106 CPU)
- Enforce path length at order creation time with revert if exceeded
- Update order_handler, exchange_router, adl_handler, liquidation_handler,
  swap_utils, increase_position_utils, decrease_position_utils
- All swap path tests pass including two_hop and boundary cases
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.

perf: use fixed-size array for swap_path to eliminate heap allocation overhead

1 participant