ChartsOrg/Charts

Charts framework takes a long time to build

drewster99 opened this issue · 0 comments

What did you do?

ℹ Clean Xcode derived data, open Charts.xcworkspace, hit Command-B to build

What did you expect to happen?

ℹ Build should be quick.

What happened instead?

ℹ Takes almost 20 seconds on M1 Max macbook pro (Sonoma 14.1.1, Xcode 15.0.1)

DGCharts Environment

DGCharts version/Branch/Commit Number: 5.0.0 / master / e516b04
Xcode version: 15.0.1
Swift version: 5.9
Platform(s) running DGCharts: iOS, macOS
macOS version running Xcode: Sonoma 14.1.1

Demo Project

ℹ Using just the macOS demo project that's included in the Charts.xcworkspace.

Details

Looking into this further, the Xcode build timeline shows all the Swift files that are part of the DGCharts framework being compiled sequentially. This is due to Compilation Mode being set to Whole Module (rather than Incremental) for Debug builds:

Xcode build timeline

Adding -Xfrontend -warn-long-expression-type-checking=50 to OTHER_SWIFT_FLAGS, which causes the Swift compiler to emit warnings for expressions that take longer than 50ms to type-check, we do see some warnings that indicate Swift is taking a long time to type check some expressions:

image

These are all in ChartAnimationEasing.swift. The worst are these offenders:

image image image

Looking at the other build settings:

  • Eager Linking should generally be enabled (Yes) to support better parallelization during builds (see WWDC 2022 video: https://developer.apple.com/videos/play/wwdc2022/110364/)
  • Enable Module Verifier should be No for Debug builds, as this gets in the way of parallelization during builds also.
  • Compilation Mode should be Incremental for Debug builds, but Whole Module for Release.

RECOMMENDATIONS

  1. Set Eager Linking build setting to Yes for Charts framework target
  2. Set Enable Module Verifier build setting to No for Debug builds
  3. Set Compilation Mode to Incremental for Debug builds
  4. Add -Xfrontend -warn-long-expression-type-checking=50 (or perhaps use 100) to OTHER_SWIFT_FLAGS so the Swift compiler will emit warnings for expressions that take a long time to type-check. The number after the = is the number of milliseconds threshold, above which warnings will be emitted.
  5. Refactor the slow type-checking hotspots identified above.