Sitelet https://github.com/starkware-libs/cairo/pull/10124
Skip to content

performance(general): Rewrite join into format - removing intermediary strings. - #10124

Merged
orizi merged 1 commit into
mainfrom
orizi/06-18-performance_general_rewrite_join_into_format_-_removing_intermediary_strings
Jun 18, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/06-18-performance_general_rewrite_join_into_format_-_removing_intermediary_strings

Conversation

@orizi

@orizi orizi commented Jun 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Replaces uses of .join(...) (which allocates an intermediate String) with itertools' .format(...) (which formats lazily without allocation) across the codebase. This applies to iterator chains that were calling .join(...) directly or after .map(...), switching them to use the Itertools::format adapter instead.


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?

.join(...) on iterators collects all elements into an intermediate String before writing the result. Itertools::format(...) is a lazy adapter that writes each element directly into the formatter without allocating an intermediate buffer, reducing unnecessary heap allocations in string formatting paths.


What was the behavior or documentation before?

Iterator chains used .join(separator) (or .map(...).join(separator)) to produce formatted strings, allocating an intermediate String in the process.


What is the behavior or documentation after?

The same iterator chains use .format(separator) from itertools::Itertools, producing identical output while avoiding intermediate allocations.


Related issue or discussion (if any)


Additional context

In one case (PluginTypeInfo::impl_header), an explicit .iter() call was added before .format(...) since the return type of impl_generics is a Vec, which required going through an iterator first. All other changes are straightforward substitutions.

orizi commented Jun 18, 2026 •

Copy link
Copy Markdown
Collaborator Author

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

@orizi
orizi marked this pull request as ready for review June 18, 2026 08:36
@cursor

cursor Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Behavior-preserving formatting refactors with no logic or API changes; remaining .join usages are intentional.

Overview
Replaces .join(separator) with itertools::Itertools::format(separator) across formatter, lowering, semantic diagnostics, plugins, Starknet plugins, runner, Sierra generator, and test runner code paths.

Formatted output stays the same; iterators now write directly into write! / format! instead of allocating an intermediate joined String. A few call sites add .iter() where the value is a Vec (e.g. PluginTypeInfo::impl_header). equality_analysis also imports Itertools for the debug printer change.

Some derive helpers (e.g. struct Default) still use .join where a owned string is required before formatdoc!—only the sites in the diff were switched.

Reviewed by Cursor Bugbot for commit 13f5681. Bugbot is set up for automated code reviews on this repo. Configure here.

@TomerStarkware TomerStarkware left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:lgtm:

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

@orizi
orizi changed the base branch from orizi/06-18-bugfix_formatter_sort_merged_items_via_compare_names to graphite-base/10124 June 18, 2026 09:00
@orizi
orizi force-pushed the graphite-base/10124 branch from 294280c to 15dc17c Compare June 18, 2026 09:01
@orizi
orizi force-pushed the orizi/06-18-performance_general_rewrite_join_into_format_-_removing_intermediary_strings branch from 3ace186 to 13f5681 Compare June 18, 2026 09:01
@orizi
orizi changed the base branch from graphite-base/10124 to main June 18, 2026 09:01
@orizi
orizi enabled auto-merge June 18, 2026 09:01
@orizi
orizi added this pull request to the merge queue Jun 18, 2026
Merged via the queue into main with commit 77005ea Jun 18, 2026
106 checks passed
@orizi
orizi deleted the orizi/06-18-performance_general_rewrite_join_into_format_-_removing_intermediary_strings branch June 21, 2026 12:15
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