0

In swift the compilation time is really slow the amount of code in your project increases. So i was looking for ways to reduce that time. One approach maybe is to use language keywords like final or static to change the way the compiler handles the code in this case using static and dynamic dispatch.

But as far i read is better to avoid runtime overhead reducing dynamic dispatch

So my first doubt is if doing all i can in runtime using more dynamic dispatch reduce compile times at cost of the runtime overhead.

My second doubt is runtime overhead is so bad? that you could sacrifice compile time in order to reduce the overhead?

sepp2k
  • 363,768
  • 54
  • 674
  • 675
Mariano
  • 79
  • 6
  • 1
    In general, static vs dynamic dispatch isn't a cause of compile speed problems. Generally the problem is type-checking, and in most cases in my experience, if you're having really slow build times, the problem is not the amount of code, but rather one or two places that take a very long time because of an exponential type-checking problem. The most common cause in my experience is chained +, like `"string" + x + "more"`. + takes a very long time to type check and chaining it is really bad for compile times. – Rob Napier Jun 05 '17 at 05:32
  • @RobNapier thanks that helps me a lot, so in terms of performance its better to avoid dynamic dispatch to reduce runtime overhead?, and also i don't know if compile code as frameworks or libraries is possible in all languages, but i read that is a way to reduce compile times because the compiler don't do all the process for that frameworks or libraries – Mariano Jun 05 '17 at 05:53

1 Answers1

0

To the title question:

Compilation time is a function of:

  • Scanning
  • Parsing
  • Symbol Management
  • Semantic Verification
  • Type Checking (as @Ron Napier pointed out)
  • Code path optimizations
  • Emitting machine code or LLVM-IR

Each one of the steps above will be a function of what techniques are used to accomplish each of the results for the step and the size/complexity of your source file. The is some flexibility in the order and number of steps.

Using dynamic dispatch is a run-time function and worthy of another question.

Frank C.
  • 7,758
  • 4
  • 35
  • 45
  • Thats what i wanted to know, i leave this other answer that someone give me in other forum, i think its also really well explained https://softwareengineering.stackexchange.com/questions/350165/use-more-dynamic-dispatch-could-reduce-compile-time/350175#350175 – Mariano Jun 05 '17 at 19:34