Optimize simplifying paths for faster project generation #857
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.
We are using XcodeGen with a ~3000 files project, and the project generation for it takes about 3s.
I wanted to know what's taking time, and Instruments told me that the time of
Path.simplifyingParentDirectoryReferences
calls reaches almost 30% of the whole.I also found that repeated invocation of
Path.+
is time-consuming as it causes String copying and conversion between NSString.This looks kind of overkill to me, because most of the paths in our project don't include parent path reference nor have trailing slashes. So, this change avoids
Path.+
when the path does not include..
in its middle, while manually removing trailing slashes with a simpler way instead.It cuts off our project generation time down to about 2/3 (2s). I think it's not common case where many paths in a project needs the actual simplification, but the overhead of this change for these cases would be ignorable.
I didn't completely rewrite the whole function to minimize the possibility of regression for special cases. I want to know if even this fast-path has any patterns to cause regression.