Skip to content

perf: cache successor params to avoid O(P×A) cloning in arg demotion#7556

Open
Fibonacci747 wants to merge 1 commit intoFuelLabs:masterfrom
Fibonacci747:perf/reduce-arg-demotion-allocs
Open

perf: cache successor params to avoid O(P×A) cloning in arg demotion#7556
Fibonacci747 wants to merge 1 commit intoFuelLabs:masterfrom
Fibonacci747:perf/reduce-arg-demotion-allocs

Conversation

@Fibonacci747
Copy link

demote_block_signature called get_succ_params() inside a nested loop over predecessors and demotable arguments. Each call cloned the entire arguments vector just to access a single element by index. With P predecessors, A demotable args, and N total args, this resulted in P×A×N unnecessary Value copies instead of P×N.

Moved get_succ_params() call outside the inner loop and cache the result, reducing vector cloning from O(P×A) to O(P) per block.

@Fibonacci747 Fibonacci747 requested a review from a team as a code owner February 16, 2026 07:56
@fuel-cla-bot
Copy link

fuel-cla-bot bot commented Feb 16, 2026

Thanks for the contribution! Before we can merge this, we need @Fibonacci747 to sign the Fuel Labs Contributor License Agreement.

@cursor
Copy link

cursor bot commented Feb 16, 2026

PR Summary

Low Risk
Small, localized performance change that only alters how often get_succ_params() is called; functional behavior should remain unchanged aside from potential indexing/panic if assumptions were previously masked.

Overview
Improves the arg-demotion optimization by caching a predecessor block’s successor parameters (get_succ_params) once per predecessor in demote_block_signature, instead of re-fetching/cloning them for each demoted argument.

This reduces redundant Vec<Value> cloning from O(P×A) to O(P) per block while keeping IR transformation behavior the same.

Written by Cursor Bugbot for commit fa01b95. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

for (arg_idx, _arg_val, arg_var) in &arg_vars {
// Get the value which is being passed to the block at this index.
let arg_val = pred.get_succ_params(context, &block)[*arg_idx];
let arg_val = params[*arg_idx];
Copy link

Choose a reason for hiding this comment

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

Cached params causes silent no-op replacement for duplicate values

Medium Severity

When the same Value is passed at multiple demotable argument positions from the same predecessor (e.g., br block(V, V)), caching get_succ_params before the inner loop causes incorrect behavior. The first iteration's replace_values replaces ALL occurrences of V in the terminator with get_local_val_0. On the next iteration, replace_values with {V → get_local_val_1} becomes a silent no-op since V no longer exists in the terminator. The result is the terminator passing the wrong GetLocal pointer for subsequent duplicate positions.

Fix in Cursor Fix in Web

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments