Skip to content

perf(agglayer): selective frontier load/save in B2AGG processing#2752

Open
mmagician wants to merge 3 commits intomainfrom
worktree-b2agg-benchmark-populated-frontier
Open

perf(agglayer): selective frontier load/save in B2AGG processing#2752
mmagician wants to merge 3 commits intomainfrom
worktree-b2agg-benchmark-populated-frontier

Conversation

@mmagician
Copy link
Copy Markdown
Collaborator

@mmagician mmagician commented Apr 10, 2026

Summary

  • Replaces unconditional load/save of all 32 LET frontier entries with selective operations based on the bit pattern of num_leaves
  • load_let_frontier_selective: only loads entries where bit h=1 (entries that will be READ by append_and_update_frontier)
  • save_let_frontier_selective: only saves entries where bit h=0 (entries that were WRITTEN by append_and_update_frontier)
  • Halves the number of storage map syscalls from 128 to 64 per B2AGG note consumption
  • Adds benchmarks with pre-populated frontier (2^31 and 2^31-1 leaves) to measure impact across access patterns

Cycle counts (note_execution)

Scenario Before After Savings
Empty tree (0 leaves) 145,555 116,287 -29,268 (20%)
Populated (2^31 leaves, mostly writes) 145,546 114,545 -31,001 (21%)
Populated (2^31-1 leaves, mostly reads) 140,578 60,204 -80,374 (57%)

Turns out that #2618 was not merged into main nor next (by commit history, it looks like it was merged into agglayer branch short after agglayer got merged into next).
See #2753

Test plan

  • bridge_out_consecutive (32 sequential B2AGG notes verified against Solidity roots)
  • bridge_out_fails_with_unregistered_faucet
  • b2agg_note_non_target_account_cannot_consume
  • b2agg_note_reclaim_scenario
  • All bridge_in tests pass
  • make lint passes

🤖 Generated with Claude Code

@mmagician mmagician force-pushed the worktree-b2agg-benchmark-populated-frontier branch 2 times, most recently from 6acc903 to e8704e4 Compare April 10, 2026 10:27
@mmagician mmagician requested a review from Fumuran April 10, 2026 10:29
@mmagician mmagician changed the base branch from next to mmagician-claude/squash-pr-2618 April 10, 2026 10:31
@mmagician mmagician force-pushed the mmagician-claude/squash-pr-2618 branch from 90286c5 to 949890c Compare April 10, 2026 10:38
@mmagician mmagician force-pushed the worktree-b2agg-benchmark-populated-frontier branch from e8704e4 to 0273ef4 Compare April 10, 2026 10:40
@mmagician mmagician changed the title perf(agglayer): selective frontier load/save in bridge-out perf(agglayer): selective frontier load/save in B2AGG processing Apr 10, 2026
@mmagician mmagician added no changelog This PR does not require an entry in the `CHANGELOG.md` file agglayer PRs or issues related to AggLayer bridging integration benchmarks Improvements to benchmarks pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority labels Apr 10, 2026
@mmagician mmagician marked this pull request as ready for review April 13, 2026 08:36
Base automatically changed from mmagician-claude/squash-pr-2618 to main April 15, 2026 10:47
Replace unconditional load/save of all 32 LET frontier entries with
selective operations based on the bit pattern of num_leaves:

- load_let_frontier_selective: only loads entries where bit h=1
  (entries that will be READ by append_and_update_frontier)
- save_let_frontier_selective: only saves entries where bit h=0
  (entries that were WRITTEN by append_and_update_frontier)

This halves the number of storage map syscalls from 128 to 64 per
B2AGG note consumption. Cycle savings vary by frontier occupancy:
- Empty tree (0 leaves): 145k -> 116k (-20%)
- Populated tree (2^31-1 leaves): 140k -> 60k (-57%)

Also adds benchmarks with pre-populated frontier states (2^31 and
2^31-1 leaves) to measure the impact across different access patterns.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mmagician mmagician force-pushed the worktree-b2agg-benchmark-populated-frontier branch from 0273ef4 to eebff52 Compare April 16, 2026 13:41
Copy link
Copy Markdown
Contributor

@Fumuran Fumuran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you! I left a few (mostly format) nits inline

Comment thread crates/miden-agglayer/asm/agglayer/bridge/bridge_out.masm
Comment thread crates/miden-agglayer/asm/agglayer/bridge/bridge_out.masm
Comment thread crates/miden-agglayer/asm/agglayer/bridge/bridge_out.masm Outdated
Comment thread crates/miden-agglayer/asm/agglayer/bridge/bridge_out.masm Outdated
Comment thread crates/miden-agglayer/asm/agglayer/bridge/bridge_out.masm
Comment thread crates/miden-agglayer/asm/agglayer/bridge/bridge_out.masm Outdated
- Add v0.15.0 CHANGELOG entry for selective frontier optimization
- Add newline after stack comment to separate logic blocks
- Move add.1 to same line as swap u32shr.1 swap
- Use if.false instead of eq.0 if.true for bit check
- Add stack comment after double_word_array::set

https://claude.ai/code/session_01GjjUe9KUggLJMAdiuBw8vk
Comment thread CHANGELOG.md
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that we should remove the whole changelog before v0.14.1 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agglayer PRs or issues related to AggLayer bridging integration benchmarks Improvements to benchmarks no changelog This PR does not require an entry in the `CHANGELOG.md` file pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants