Skip to content

perf: avoid extra Vec allocation in split_structs#9471

Open
Galoretka wants to merge 2 commits intostarkware-libs:mainfrom
Galoretka:perf/lowering-split-structs-avoid-vec-alloc
Open

perf: avoid extra Vec allocation in split_structs#9471
Galoretka wants to merge 2 commits intostarkware-libs:mainfrom
Galoretka:perf/lowering-split-structs-avoid-vec-alloc

Conversation

@Galoretka
Copy link
Copy Markdown
Contributor

Summary

Replace output_split.vars.to_vec() in the StructDestructure handling with output_split.vars.iter().cloned() so we no longer allocate a temporary Vec just to iterate over it.


Type of change

  • Performance improvement

Why is this change needed?

Avoid per-statement heap allocation in a hot optimization pass.

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

@orizi reviewed 1 file and made 1 comment.
Reviewable status: all files reviewed (commit messages unreviewed), 1 unresolved discussion (waiting on @Galoretka).


crates/cairo-lang-lowering/src/optimizations/split_structs.rs line 177 at r1 (raw file):

                                ctx.var_remapper.renamed_vars.insert(*output, new_var).is_none()
                            )
                        }

Suggestion:

                        for (output, new_var) in zip_eq(&stmt.outputs, &output_split.vars) {
                            assert!(
                                ctx.var_remapper.renamed_vars.insert(*output, new_var.clone()).is_none()
                            )
                        }

Copy link
Copy Markdown
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

:lgtm:

@orizi reviewed 1 file and all commit messages, made 1 comment, and resolved 1 discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Galoretka).

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.

3 participants