Skip to content

Comments

feat: add memory allocation tracker#243

Merged
Timi16 merged 1 commit intoTimi16:mainfrom
ScriptedBro:feature/memory-tracker
Feb 23, 2026
Merged

feat: add memory allocation tracker#243
Timi16 merged 1 commit intoTimi16:mainfrom
ScriptedBro:feature/memory-tracker

Conversation

@ScriptedBro
Copy link
Contributor

Summary

Adds memory allocation tracking and reporting for contract execution to help developers understand memory footprint and optimize usage.

What changed

  • Hooked memory tracking into contract execution in ContractExecutor::execute
  • Captures memory growth snapshots at key execution stages
  • Tracks:
    • total allocation count
    • total bytes allocated
    • peak memory usage
    • top 5 largest tracked allocations
  • Displays a memory allocation summary section after execution
  • Includes memory_summary in JSON output for run --json
  • Added unit tests for memory tracking totals/peak/top-allocation ordering

Acceptance Criteria

  • Allocation count tracked correctly
  • Peak memory usage displayed
  • Top 5 allocations listed
  • Memory summary shown in output
  • Included in JSON output

Validation

  • cargo test inspector::budget:: --lib
  • Manual verification with:
    • soroban-debug run --contract tests/fixtures/wasm/counter.wasm --function increment
    • soroban-debug run --contract tests/fixtures/wasm/counter.wasm --function increment --json

Notes

  • "Top 5 allocations" reports up to 5 tracked allocation events (checkpoint-based memory growth deltas). Small contracts may show fewer than 5 entries.

Closes #203

Issue: #203

@Timi16 Timi16 merged commit fb21742 into Timi16:main Feb 23, 2026
3 of 4 checks 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.

Add Memory Allocation Tracker

2 participants