XCLogParser icon indicating copy to clipboard operation
XCLogParser copied to clipboard

Fix XCLogParser function/typechecking recognition for modern Xcode versions

Open Iron-Ham opened this issue 10 months ago • 4 comments

Closes https://github.com/MobileNativeFoundation/XCLogParser/issues/190

Since xclogparser was last updated, there have been various changes in the way that Xcode builds are handled:

  1. The prefix for swift compilation steps is now SwiftCompile, not CompileSwift. This changes build step recognition in BuildStep.swift, but also changes the various regular expressions used for identifying these steps.
  2. Standard swift compilation steps are now batch compilation steps – similar in behavior to the swiftAggregatedCompilation step that is already defined. You can read more about that here: https://github.com/swiftlang/swift/blob/main/docs/CompilerPerformance.md#compilation-modes
  3. As an addendum to (2): Since these batch steps are asynchronous and parallelized, there are situations where substep function and type check times may be duplicated. As such, we ensure we're de-duplicating them by passing them through a Set.

In short: this allows the type checking and function time data to appear in the outputs without causing memory explosions or runtime explosions.

Things to note:

  1. Since these compilation steps are all batch steps… while this does cause the Slowest Swift Files to appear in the HTML reporter, this isn't really even a valid metric anymore since it's the measurement of n file compilations. XYZ.swift didn't take 20 seconds to compile – rather, it and its batch of files took that time. We should probably fully remove this section from the HTML output, unless the compilation mode is setup for single files. For now, I'm leaving it as is.
  2. This represents a hard version upgrade. It will not work for older versions of Xcode that don't use this build system.
  3. I haven't tested single file compilation mode.
  4. Module time compilation isn't reporting any differently than it was previously, however, I always found this to be a somewhat flawed metric: it's showing the aggregate time of the module and its dependencies. If we have a 5 line module that depends on a gigantic module, we often run into the situation where the small module reports a compilation time ~1s larger than its dependent module.

🤖 Copilot Generated PR Description and Outline

This pull request includes several changes to improve the parsing and reporting of Swift compilation steps in the XCLogParser project. The changes focus on updating patterns for Swift compilation, enhancing data structures for performance, and refining the reporting logic.

Changes to update CompileSwift prefix:

  • Sources/XCLogParser/parser/BuildStep.swift: Updated the prefix from CompileSwift to SwiftCompile in the DetailStepType enum.
  • Sources/XCLogParser/parser/IDEActivityLogSection+Parsing.swift: Updated the regular expression pattern to match SwiftCompile instead of CompileSwift.
  • Sources/XCLogParser/parser/ParserBuildSteps.swift: Changed the pattern in swiftcArchRegexp to match SwiftCompile instead of CompileSwift.

Changes to improve handling of Swift function and type check times:

  • Sources/XCLogParser/reporter/HtmlReporter.swift: Replaced arrays with sets for swiftFunctionTimes and swiftTypeCheckTimes to avoid duplicates and ensure unique entries. [1] [2]

Conformance to Hashable protocol:

  • Sources/XCLogParser/parser/SwiftFunctionTime.swift: Made SwiftFunctionTime conform to the Hashable protocol.
  • Sources/XCLogParser/parser/SwiftTypeCheck.swift: Made SwiftTypeCheck conform to the Hashable protocol.

Screenshots and Outputs

HTML Screenshot

Screenshot 2025-03-13 at 10 28 22 AM

FlatJSON Output (Redacting app name)

Excerpt 1:

[
  {
    "type" : "main",
    "fetchedFromCache" : false,
    "errorCount" : 0,
    "compilationEndTimestamp" : 1741873280.071251,
    "errors" : [

    ],
    "schema" : "<REDACTED>",
    "compilationDuration" : 451.705482006073,
    "endDate" : "2025-03-13T13:41:39.543000Z",
    "detailStepType" : "none",
    "startDate" : "2025-03-13T13:33:48.366000Z",
    "parentIdentifier" : "",
    "buildIdentifier" : "Hesham’s MacBook Pro_C73D272C-AA17-42E3-99B2-77AC929317F4",
    "warningCount" : 143,
    "notes" : [
      {
        "title" : "Run script build phase 'Set Bundle Version' will be run during every build because the option to run the script phase \"Based on dependency analysis\" is unchecked.",
        "startingLineNumber" : 0,
        "type" : "note",
        "severity" : 0,
        "characterRangeEnd" : 0,
        "detail" : "note: Run script build phase 'Set Bundle Version' will be run during every build because the option to run the script phase \"Based on dependency analysis\" is unchecked. (in target 'PullsWidget' from project 'REDACTED')\rnote: Run script build phase 'Set Bundle Version' will be run during every build because the option to run the script phase \"Based on dependency analysis\" is unchecked. (in target 'NotificationService' from project 'REDACTED')\rnote: Run script build phase 'Set Bundle Version' will be run during every build because the option to run the script phase \"Based on dependency analysis\" is unchecked. (in target 'IntentsService' from project 'REDACTED')\rnote: Run script build phase 'SwiftLint' will be run during every build because the option to run the script phase \"Based on dependency analysis\" is unchecked. (in target 'REDACTED' from project 'REDACTED')\rnote: Run script build phase 'Crashlytics' will be run during every build because the option to run the script phase \"Based on dependency analysis\" is unchecked. (in target 'REDACTED' from project 'REDACTED')\rnote: Run script build phase 'Set Bundle Version' will be run during every build because the option to run the script phase \"Based on dependency analysis\" is unchecked. (in target 'REDACTED' from project 'REDACTED')\r\/Users\/zer0\/Developer\/REDACTED\/mobile-ios\/.build\/Xcode\/DerivedData\/SourcePackages\/checkouts\/firebase-ios-sdk\/Package.swift: warning: DEFINES_MODULE was set, but no umbrella header could be found to generate the module map (in target 'Firebase' from project 'Firebase')\rnote: Run script build phase 'Set Bundle Version' will be run during every build because the option to run the script phase \"Based on dependency analysis\" is unchecked. (in target 'ContributionGraphWidget' from project 'REDACTED')",
        "startingColumnNumber" : 0,
        "endingColumnNumber" : 0,

Excerpt 2:

    "documentURL" : "file:\/\/\/Users\/zer0\/Developer\/REDACTED\/mobile-ios\/Modules\/_REDACTEDMarkdown_Routes\/Sources\/UIResponder+WebViewPreviewable.swift",
    "endDate" : "2025-03-13T13:40:00.822000Z",
    "swiftFunctionTimes" : [
      {
        "file" : "file:\/\/\/Users\/zer0\/Developer\/REDACTED\/mobile-ios\/Modules\/_REDACTEDMarkdown_Routes\/Sources\/UIResponder+WebViewPreviewable.swift",
        "startingColumn" : 17,
        "signature" : "instance method _REDACTEDbMarkdown_Routes.(file).UIResponder extension.onPreview(url:)@\/Users\/zer0\/Developer\/REDACTED\/mobile-ios\/Modules\/_REDACTEDMarkdown_Routes\/Sources\/UIResponder+WebViewPreviewable.swift:7:17",
        "durationMS" : 0.73,
        "startingLine" : 7,
        "occurrences" : 1
      },
      {
        "startingColumn" : 17,
        "signature" : "instance method _REDACTEDMarkdown_Routes.(file).UIResponder extension.presentPreview(url:)@\/Users\/zer0\/Developer\/REDACTED\/mobile-ios\/Modules\/_REDACTEDMarkdown_Routes\/Sources\/UIResponder+WebViewPreviewable.swift:11:17",
        "durationMS" : 0.37,
        "occurrences" : 1,
        "startingLine" : 11,
        "file" : "file:\/\/\/Users\/zer0\/Developer\/REDACTED\/mobile-ios\/Modules\/_REDACTEDMarkdown_Routes\/Sources\/UIResponder+WebViewPreviewable.swift"
      }
    ]
  },

Iron-Ham avatar Mar 13 '25 14:03 Iron-Ham

@Iron-Ham what is the minimum Xcode version this will work with? I assume many of the users of this repo work with newer Xcode versions, so as long as it's Xcode 16 and up, we should be good. @pepicrft thoughts?

AvdLee avatar Jul 14 '25 12:07 AvdLee

@Iron-Ham any updates on this PR? 🙏

AvdLee avatar Sep 11 '25 09:09 AvdLee

@AvdLee apologies, I haven't had the time to dive back into this, and the context is a bit fuzzy at this point. Happy to take a look once some of the iOS26 dust settles on my end – likely tomorrow or this weekend!

Appreciate your patience

Iron-Ham avatar Sep 11 '25 17:09 Iron-Ham

@Iron-Ham thanks for the heads up, that timing works! 🚀

AvdLee avatar Sep 11 '25 17:09 AvdLee