Skip to content

buildifier: improve Windows runner performance#1404

Merged
AnnaSvalova merged 2 commits intobazelbuild:mainfrom
rdesgroppes:improve-buildifier-runner-performance-on-windows
Nov 6, 2025
Merged

buildifier: improve Windows runner performance#1404
AnnaSvalova merged 2 commits intobazelbuild:mainfrom
rdesgroppes:improve-buildifier-runner-performance-on-windows

Conversation

@rdesgroppes
Copy link
Contributor

@rdesgroppes rdesgroppes commented Oct 15, 2025

This change aims to improve the buildidier's runner performance on Windows where it can sometimes take minutes to complete.

It consists in replacing the slow COM Scripting.FileSystemObject with a "native" PowerShell Get-ChildItem -Recurse for file discovery, and batch buildifier invocations (100 files at a time) instead of invoking once per file.

This improves performance on large codebases (like from about 2 minutes to less than 3 seconds).

Notes:

  • cross-process COM calls add latency, whereas Get-ChildItem is a compiled "cmdlet",
  • by default, Get-ChildItem doesn't recurse into symbolic links to directories, which is consistent with the current implementation that explicitly avoids entering ReparsePoints,
  • batching files passed to buildifier reduces process creation overhead, with a limit to account for Windows command line length limitations.

$i = 0;^
while ($i -lt $Files.Count)^
{^
$Batch = $Files[$i..($i + 99)];^
Copy link
Collaborator

Choose a reason for hiding this comment

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

LGTM, but could you add a comment here please? About Windows' command line length limitation and 100 files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AnnaSvalova Done in 2nd commit (f5fad4e).

This change aims to improve the `buildidier`'s runner performance on
Windows where it can sometimes take minutes to complete.

It consists in replacing the slow COM `Scripting.FileSystemObject` with
a "native" PowerShell `Get-ChildItem -Recurse` for file discovery, and
batch `buildifier` invocations (100 files at a time) instead of invoking
once per file.

This improves performance on large codebases (like from about 2 minutes
to less than 3 seconds).

Notes:
- cross-process COM calls add latency, whereas `Get-ChildItem` is a
  compiled "cmdlet".
- by default, `Get-ChildItem` doesn't recurse into symbolic links to
  directories, which is consistent with the current implementation that
  explicitly avoids entering `ReparsePoint`s,
- batching files passed to `buildifier` reduces process creation
  overhead, with a limit to account for Windows command line length
  limitations.
@rdesgroppes rdesgroppes force-pushed the improve-buildifier-runner-performance-on-windows branch from dd6566f to f5fad4e Compare November 6, 2025 13:23
@AnnaSvalova AnnaSvalova merged commit 61dad1f into bazelbuild:main Nov 6, 2025
2 checks passed
@rdesgroppes rdesgroppes deleted the improve-buildifier-runner-performance-on-windows branch November 6, 2025 14:25
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.

2 participants