Skip to content

performance(lowering): Removed many interim vectors for extern fn processing.#9569

Merged
orizi merged 1 commit intomainfrom
orizi/01-29-performance_lowering_removed_many_interim_vectors_for_extern_fn_processing
Feb 3, 2026
Merged

performance(lowering): Removed many interim vectors for extern fn processing.#9569
orizi merged 1 commit intomainfrom
orizi/01-29-performance_lowering_removed_many_interim_vectors_for_extern_fn_processing

Conversation

@orizi
Copy link
Collaborator

@orizi orizi commented Jan 29, 2026

Summary

Refactored the extern_facade_return_tys function to return a slice instead of a vector, improving performance by avoiding unnecessary allocations. Also modified extern_facade_expr to accept an iterator instead of a vector, allowing for more flexible usage patterns. Updated all call sites to accommodate these changes, resulting in cleaner code that avoids unnecessary vector allocations and copies.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

The previous implementation was creating unnecessary vector allocations when processing extern function return types. By changing the return type to a slice and accepting iterators instead of vectors, we reduce memory allocations and improve performance in the lowering phase.


What was the behavior or documentation before?

Previously, extern_facade_return_tys would always allocate a new vector even when returning a single type, and extern_facade_expr required a fully constructed vector to be passed in, leading to additional allocations and copies.


What is the behavior or documentation after?

Now extern_facade_return_tys returns a slice (either a reference to the existing tuple types or a single-element slice), and extern_facade_expr accepts any exact-size iterator of variable IDs, allowing callers to avoid unnecessary allocations.


Additional context

This change is part of ongoing efforts to optimize the compiler's memory usage and performance. The modifications maintain the same functionality while reducing allocations in the hot path of the lowering phase.

@orizi orizi requested a review from TomerStarkware January 29, 2026 15:20
@reviewable-StarkWare
Copy link

This change is Reviewable

@orizi orizi requested a review from eytan-starkware January 29, 2026 15:20
Copy link
Collaborator Author

orizi commented Jan 29, 2026

@orizi orizi marked this pull request as ready for review January 29, 2026 15:21
Copy link
Contributor

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

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

@eytan-starkware reviewed 4 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @orizi and @TomerStarkware).


crates/cairo-lang-lowering/src/lower/mod.rs line 2321 at r1 (raw file):

}

/// Binds input references when matching on extern functions.

Update comment

@orizi orizi force-pushed the orizi/01-29-performance_lowering_removed_many_interim_vectors_for_extern_fn_processing branch from ccca11f to ae9d636 Compare February 1, 2026 11:31
Copy link
Collaborator Author

@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 made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @eytan-starkware and @TomerStarkware).


crates/cairo-lang-lowering/src/lower/mod.rs line 2321 at r1 (raw file):

Previously, eytan-starkware wrote…

Update comment

Done.

@orizi orizi changed the base branch from orizi/01-29-feature_semantic_allow_immediate_consumption_of_ref_self_of_tempraries to graphite-base/9569 February 1, 2026 17:17
@orizi orizi force-pushed the graphite-base/9569 branch from 06c3c66 to de768f3 Compare February 1, 2026 17:18
@orizi orizi force-pushed the orizi/01-29-performance_lowering_removed_many_interim_vectors_for_extern_fn_processing branch from ae9d636 to 0fa8e71 Compare February 1, 2026 17:18
@orizi orizi changed the base branch from graphite-base/9569 to main February 1, 2026 17:18
Copy link
Contributor

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

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

@eytan-starkware reviewed 1 file and all commit messages, and resolved 1 discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @TomerStarkware).

Copy link
Contributor

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

@eytan-starkware made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @TomerStarkware).

@orizi orizi added this pull request to the merge queue Feb 3, 2026
Merged via the queue into main with commit b20f636 Feb 3, 2026
108 checks passed
@orizi orizi deleted the orizi/01-29-performance_lowering_removed_many_interim_vectors_for_extern_fn_processing branch February 3, 2026 12:17
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