Functionality unused in the app itself and its influence on the app's size

Hi everyone,

Could you tell me and, if possible, provide a reference to the source, does the code written in the module and not used in this module increases the size of my app?

In details, my case is as follows: I have a structure in some module of my project and would like to make it Equatable in this module (so Swift synthesises Equatable conformance for me). I would like this Equatable conformance for testing purposes in the different target.

So, my colleague Rusty told me that this will make my production code bigger in size, though as far as I know Swift's compiler is smart enough not to add unused functionality to the build (such as SwiftUI Previews), but I am not sure at what extent it can do it.

Thank you, feel free to ask me to make some details more clear

Would be a very quick one to do an experiment with and find out.

(My guess, as the furthest thing from a compiler expert, is that since it's a protocol conformance, it'd have to be included, and thus would add size to your code. But I'd also expect the increase to be tiny, far smaller than would be worth worrying about in any but extreme cases.)

2 Likes

That sounds plausible to me. I don't know if we have anything in the compiler that deletes unused conformances in non-libraries, might be worth filing if we don't.

2 Likes

I have a thought on my question again, and the case, when you need this conformance to keep dynamically (e.g. you are iterating over an array and trying to get an element that conforms to Equatable or something), came to my mind. And I don't think it is possible for compiler to foresee this