ChartsOrg / Charts

Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.
Apache License 2.0
27.48k stars 5.98k forks source link

Shorten type checking times by shortening expressions and avoiding type conversions #5105

Open idrougge opened 11 months ago

idrougge commented 11 months ago

I noticed that DGCharts amounted to a large portion of the compile times of our app, so I measured the times for evaluating expressions and function bodies by adding the below build flags:

-Xfrontend -warn-long-function-bodies=<ms>
-Xfrontend -warn-long-expression-type-checking=<ms>

It turned out that certain functions and expressions had evaluation times close to one second on an M1 Mac, so I added some help for the compiler to shorten those checking times.

As a result of these changes, the compile times have gone down from 6 s for the entire package to only 4 s — a 33 % decrease. Certain files still make out the bulk of the total compile time so a further refactoring of those files could enable higher parallelisation of compilation, but that would make this PR too big to review.

Goals :soccer:

Shorter compile times.

Implementation Details :construction:

  1. Bracketing parts of certain long expressions such as -0.5 * (sqrt(1.0 - position * position) - 1.0)
  2. Removing type conversions from Double to Double such as Double( sqrt(1 - position * position) )
  3. Adding a guard to functions that consisted of just one big if statement
  4. Adding a type specifier to variable declarations that instead used a type initialiser on a literal such as var maxW: CGFloat = 0.0

Testing Details :mag:

The tests still run as before. To ease code review, it helps to turn on "hide white spaces" in Github's code review view.

drewster99 commented 9 months ago

Oof. Similar work done in https://github.com/danielgindi/Charts/pull/5124.