buildifier: improve Windows runner performance#1404
Merged
AnnaSvalova merged 2 commits intobazelbuild:mainfrom Nov 6, 2025
Merged
Conversation
rdesgroppes
added a commit
to DataDog/datadog-agent
that referenced
this pull request
Oct 16, 2025
### What does this PR do? Apply a last path on `buildifier`'s runner script template on Windows: - bazelbuild/buildtools#1404 ### Motivation Decrease execution time from [~2 minutes](https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/1177131952#L77) to [~2 seconds](https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/1180039154#L99). ### Describe how you validated your changes Locally (Windows VM) and in CI (1985f7f). ### Additional Notes Closes [ABLD-174](https://datadoghq.atlassian.net/browse/ABLD-174). [ABLD-174]: https://datadoghq.atlassian.net/browse/ABLD-174?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
AnnaSvalova
requested changes
Nov 6, 2025
| $i = 0;^ | ||
| while ($i -lt $Files.Count)^ | ||
| {^ | ||
| $Batch = $Files[$i..($i + 99)];^ |
Collaborator
There was a problem hiding this comment.
LGTM, but could you add a comment here please? About Windows' command line length limitation and 100 files.
Contributor
Author
There was a problem hiding this comment.
@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.
This is to address following review comment: > LGTM, but could you add a comment here please? About Windows' command > line length limitation and 100 files. (bazelbuild#1404 (comment)) References: - https://stackoverflow.com/questions/73893997/comments-in-a-long-line-powershell-code-in-a-batch-script - https://stackoverflow.com/questions/3205027/maximum-length-of-command-line-string - https://devblogs.microsoft.com/oldnewthing/20031210-00/?p=41553
dd6566f to
f5fad4e
Compare
AnnaSvalova
approved these changes
Nov 6, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.FileSystemObjectwith a "native" PowerShellGet-ChildItem -Recursefor file discovery, and batchbuildifierinvocations (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:
Get-ChildItemis a compiled "cmdlet",Get-ChildItemdoesn't recurse into symbolic links to directories, which is consistent with the current implementation that explicitly avoids enteringReparsePoints,buildifierreduces process creation overhead, with a limit to account for Windows command line length limitations.