RobertGummesson / BuildTimeAnalyzer-for-Xcode

Build Time Analyzer for Swift
MIT License
4.3k stars 260 forks source link

what does "Occurrences" mean? #92

Closed ZengSir closed 4 years ago

ZengSir commented 5 years ago

There is one result of my project: 333222.0ms (cumulative time) and 26 (occurrences) instance method disLikeButtonPressed(). What does occurrences mean? And how should I optimize? Thanks.

KingOfBrian commented 5 years ago

I'm curious too! All of my files have either 26 or 72 occurrences, which sounds like some thing is triggering the type checker a lot. Any leads on how to investigate would be great

RobertGummesson commented 5 years ago

Occurrences mean that the compiler is type checking a method or property multiple times. There's a more information about this here.

Having that said, there's something odd about the new Xcode. When the app was built, this was an irregularity but with the latest Xcode versions it's the norm to have 26-27 occurrences. I haven't had much time for this project lately and thereof haven't looked into why this is.

KingOfBrian commented 5 years ago

Interesting -- any chance you could ping the person who recommended the addition of Occurrences to see if they have any input?

iDevid commented 5 years ago

Seems that the last version is bugged, it gives everytime "26 occurrences" and the ms for methods are even higher of that for file!

RobertGummesson commented 5 years ago

While I still haven't had time to look into why the latest Xcode results in 26-27 occurrences, the medium post I linked to earlier does explain how and why you can get larger times for a method than for a file.

maxovtsin commented 4 years ago

It can happen due to Batch mode. https://github.com/apple/swift/blob/master/docs/CompilerPerformance.md#compilation-modes

If it's enabled, the compiler will try to combine multiple jobs into a single batch job and will run a single front-end invocation per such job. The issue here is once a Batch job is finished, it will unpack it, and print the same output as many times as many single jobs were in BatchJob.

In my case, the time was exactly the same for each occurrence. For parseable-output, it's trivial to recognize such a situation. Because "real_pid" will be the same, but negative sub-"pid" will be different for every sub-job. "pid": -1027, "process": { "real_pid": 26760 }

But I'm not sure it's possible to do for logs.