-
Notifications
You must be signed in to change notification settings - Fork 174
Consolidate pre- and post-clang-format Python steps to improve performance #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
jamieQ
left a comment
There was a problem hiding this 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?
| if len(self.formatters) == 0: | ||
| return "".join(lines) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
| /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 | |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
|
Thank you for this! Our repo is significantly smaller, but it took a full reformat from 72 to 29 seconds for us. |
|
@ksuther Thanks so much for testing and sharing! Wasn't expecting anyone external to Square to see this so quickly 😅 |
Consolidate the various Python formatter commands into a single invocation for changes pre
clang-formatand postclang-formatto 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.shfrom 10m53s to 6m14s (42% reduction)