0

Given the following initialiser:

init(a1: String? = nil, a2: String? = nil, .... a16: String? = nil) {
...
}

With some simple mathematics all the possible initialisers are 2^16 = 65536

Question:

Is it true that adding too many default arguments increase build time or has bad performance?

Kwnstantinos Nikoloutsos
  • 1,832
  • 4
  • 18
  • 34
  • 4
    Why would you think that? What does this have to do with the number of possible ways to pass parameters to the initialiser? – Sweeper Jul 28 '21 at 08:13
  • The number of possible ways to pass parameters equals the number of signature the compiler has to make I guess. That's why I'm asking. – Kwnstantinos Nikoloutsos Jul 28 '21 at 08:15
  • 3
    But what has that got to do with default values, wouldn’t it be the same number of ways without default values? And you say “Is it true…”, which implies you have a source for this statement so could you point us to it? – Joakim Danielson Jul 28 '21 at 08:24
  • 3
    I encourage you to use [godbolt.org](https://godbolt.org) to explore the code that the compiler generates. You'll find that the compiler inserts the default values at the call site, so the only extra things that the compiler has to generate, are the default values themselves. So the time would increase linearly, rather than combinatorially. I doubt this would matter anyway. – Sweeper Jul 28 '21 at 08:24
  • 1
    @JoakimDanielson No I don't have any source about this. I will rephrase my title – Kwnstantinos Nikoloutsos Jul 28 '21 at 08:32
  • @Sweeper That sounds correct and thanks for this tool. I had the feeling that the compiler created a new signature. Hence the exponentially growth. Thank you – Kwnstantinos Nikoloutsos Jul 28 '21 at 08:34

0 Answers0