performance(general): Rewrite join into format - removing intermediary strings. - #10124
Conversation
PR SummaryLow Risk Overview Formatted output stays the same; iterators now write directly into Some derive helpers (e.g. struct Reviewed by Cursor Bugbot for commit 13f5681. Bugbot is set up for automated code reviews on this repo. Configure here. |
TomerStarkware
left a comment
There was a problem hiding this comment.
@TomerStarkware reviewed 20 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on eytan-starkware).
294280c to
15dc17c
Compare
3ace186 to
13f5681
Compare

Summary
Replaces uses of
.join(...)(which allocates an intermediateString) 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 theItertools::formatadapter instead.Type of change
Please check one:
Why is this change needed?
.join(...)on iterators collects all elements into an intermediateStringbefore 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 intermediateStringin the process.What is the behavior or documentation after?
The same iterator chains use
.format(separator)fromitertools::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 ofimpl_genericsis aVec, which required going through an iterator first. All other changes are straightforward substitutions.