Skip to content

Conversation

@amorde
Copy link
Member

@amorde amorde commented Aug 25, 2025

Consolidate the various Python formatter commands into a single invocation for changes pre clang-format and post clang-format to reduce extra overhead involved in spinning up a new process for each step.

This makes a significant difference on a large internal monorepo with over 12k Objective-C files, reducing the time of format-objc-files-in-repo.sh from 10m53s to 6m14s (42% reduction)

Copy link
Contributor

@jamieQ jamieQ left a comment

Choose a reason for hiding this comment

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

looks reasonable to my (naive) eye! sort of a shocking performance improvement – i guess process spawning isn't free?

Comment on lines +11 to +12
if len(self.formatters) == 0:
return "".join(lines)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should this just be an error instead of ignoring it? seems like there should be at least one formatter if using this type

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah good point, but I don't think we have a good way to surface an error here. What we output will get written to the temporary file set up by the script. Perhaps we could exit with a nonzero exit code but I don't know if the script handles that well.

Comment on lines -84 to -87
/usr/bin/python3 "$DIR"/custom/LiteralSymbolSpacer.py |
/usr/bin/python3 "$DIR"/custom/InlineConstructorOnSingleLine.py |
/usr/bin/python3 "$DIR"/custom/MacroSemicolonAppender.py |
/usr/bin/python3 "$DIR"/custom/DoubleNewlineInserter.py |
Copy link
Contributor

Choose a reason for hiding this comment

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

for my own education – does each | spawn a new process?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, and since it's invoking python that means spinning up a python interpreter each time

@amorde amorde merged commit abeaf5b into master Aug 26, 2025
5 checks passed
@amorde amorde deleted the amorde/format-perf branch August 26, 2025 17:02
@ksuther
Copy link
Contributor

ksuther commented Aug 26, 2025

Thank you for this! Our repo is significantly smaller, but it took a full reformat from 72 to 29 seconds for us.

@amorde
Copy link
Member Author

amorde commented Aug 26, 2025

@ksuther Thanks so much for testing and sharing! Wasn't expecting anyone external to Square to see this so quickly 😅

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.

4 participants