Output compile durations for swift files

前端 未结 1 908
南笙
南笙 2020-12-23 11:00

Is there a way to turn output the time taken to compile a swift file during an xcode build?

I would like to compile from the command line to trigger the same build

相关标签:
1条回答
  • 2020-12-23 11:25

    You can add…

    -Xfrontend -debug-time-function-bodies
    

    …to Other Swift Flags in Swift Compiler - Custom Flags section (build settings).

    Build settings

    Note: You have to keep same order of these flags. -Xfrontend says that the next flag should be passed to the frontend. It will not work if you reverse the order.

    Then you can get compile times in your build log:

    Build log

    Which is useful when you do want to optimize compile time and also it's good to attach this kind of build log when reporting an issue to Apple Swift guys about slow compile time.

    Credit goes to Joe Pamer Errant compiler hacker. Currently an engineering manager at Apple (Swift, Clang), formerly at Microsoft (TypeScript, F#, JavaScript, .NET). He tweeted it as a response to Rob Rix question about profiling Swift compilation. It made me curious, so, I disassembled compiler, checked text section for more flags and found other hidden options. Don't use them in production code, just play with them.


    Build time of the whole project. Run following command in terminal…

    defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES
    

    …restart Xcode, clean & build and…

    Build time


    What if I have pods?

    Do same as above for your pods project

    0 讨论(0)
提交回复
热议问题