ℹ 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:
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:
These are all in ChartAnimationEasing.swift. The worst are these offenders:
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
Set Eager Linking build setting to Yes for Charts framework target
Set Enable Module Verifier build setting to No for Debug builds
Set Compilation Mode to Incremental for Debug builds
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.
Refactor the slow type-checking hotspots identified above.
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 / e516b04834b6e2072367f1366750c01c164e6545 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 toWhole Module
(rather thanIncremental
) forDebug
builds: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:These are all in ChartAnimationEasing.swift. The worst are these offenders:
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 beNo
forDebug
builds, as this gets in the way of parallelization during builds also.Compilation Mode
should beIncremental
forDebug
builds, butWhole Module
forRelease
.RECOMMENDATIONS
Eager Linking
build setting toYes
for Charts framework targetEnable Module Verifier
build setting toNo
forDebug
buildsCompilation Mode
toIncremental
forDebug
builds-Xfrontend -warn-long-expression-type-checking=50
(or perhaps use100
) 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.