Can I create a unit test that fails if compilation time exceeds an acceptable level?

Sometimes the code finds its way to the branch of my command branch, which compiles very slowly. When it comes to the point that for a few minutes we have no choice but to abandon our tasks and search for what caused it, we will lose a lot of time until we resolve it.

For the performance of our applications, we have unit tests to stop our users who are experiencing slow times, I wonder if it is possible to test the device when slow compilation times cause our tests to fail, so changes that cause slow compilation times can be identified and removed just before they kill the whole team’s time.

+5
source share
2 answers

You can add assembly settings to your project β†’ Other Swift Mark the following flag: -Xfrontend -warn-long-function-bodies=<time> where in <time> the number of ms is indicated. Then you can see warnings for any function that takes longer and corrects them.

This will not finish your tests, but the whole team will know when they encode something that takes too long to compile.

+1
source

Perhaps this requires a little extra effort, but a solution is possible:

I use 'xcodebuild clean build OTHER_SWIFT_FLAGS = "- Xfrontend -debug-time-function-body" | grep "[0-9] [0-9]. [0-9] * ms" | sort -nr> culprits.txt 'to get a text file with the time taken to compile individual methods. Then you know where the compiler gets stuck and can be optimized as long as the method that takes the longest to compile is <100ms.

a source

0
source

Source: https://habr.com/ru/post/1270776/


All Articles