Charts framework takes a long time to build
- [ X] I've read, understood, and done my best to follow the *CONTRIBUTING guidelines.
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 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:
Looking at the other build settings:
Eager Linkingshould generally be enabled (Yes) to support better parallelization during builds (see WWDC 2022 video: https://developer.apple.com/videos/play/wwdc2022/110364/)Enable Module Verifiershould beNoforDebugbuilds, as this gets in the way of parallelization during builds also.Compilation Modeshould beIncrementalforDebugbuilds, butWhole ModuleforRelease.
RECOMMENDATIONS
- Set
Eager Linkingbuild setting toYesfor Charts framework target - Set
Enable Module Verifierbuild setting toNoforDebugbuilds - Set
Compilation ModetoIncrementalforDebugbuilds - Add
-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. - Refactor the slow type-checking hotspots identified above.
maybe merge?