Skip to content

[pigeon] Switch Indent class to manage all writes with a StringBuffer#11133

Merged
auto-submit[bot] merged 4 commits intoflutter:mainfrom
srawlins:indent
Mar 2, 2026
Merged

[pigeon] Switch Indent class to manage all writes with a StringBuffer#11133
auto-submit[bot] merged 4 commits intoflutter:mainfrom
srawlins:indent

Conversation

@srawlins
Copy link
Contributor

@srawlins srawlins commented Feb 27, 2026

We change the Indent class to not accept an IOSink. Instead, it manages all writes in its own StringBuffer, and then its toString() method can be used to extract out the written text.

This dramatically reduces the number of write operations sent to the OS. Functionally, it is a no-op, but should have various performance improvements. Generating Dart files may be overall faster.

Using this PR, I find that the number of file operations is reduced from 166k operations to 3142 operations. 🎉

Fixes flutter/flutter#182958

Pre-Review Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran [the auto-formatter].
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I [linked to at least one issue that this PR fixes] in the description above.
  • I followed [the version and CHANGELOG instructions], using [semantic versioning] and the [repository CHANGELOG style], or I have commented below to indicate which documented exception this PR falls under[^1].
  • I updated/added any relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1].
  • All existing and new tests are passing.

@srawlins srawlins requested a review from tarrinneal as a code owner February 27, 2026 05:58
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the Indent class to manage all write operations with an internal StringBuffer instead of writing directly to an IOSink. This change aims to improve performance by buffering writes and reducing I/O operations. Consequently, the Indent class constructor no longer accepts a sink, and its toString() method is now used to retrieve the generated string. All call sites have been updated to instantiate Indent, use it for string construction, and then write the final content from indent.toString() to the target sink.

Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

This should also probably have a version bump.

Do you know if the formatting changes at all before the format tool runs?

@srawlins
Copy link
Contributor Author

I was wondering, when you have serveral in-flight PRs, do you just bump the version in each of them, even though you know all but one will be wrong? Just a game of merging main branch, bump version again; merge main branch, bump version again?

@tarrinneal
Copy link
Contributor

I usually do, that way whatever is ready first can land. I know when I review, seeing all passing tests helps me know something is ready to be looked at.

@srawlins srawlins added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 2, 2026
@srawlins
Copy link
Contributor Author

srawlins commented Mar 2, 2026

Version bumped.

@auto-submit auto-submit bot merged commit 173a344 into flutter:main Mar 2, 2026
81 checks passed
@srawlins srawlins deleted the indent branch March 2, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: pigeon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[pigeon] Generating code applies too many incremental writes.

2 participants