3

AppCode has a feature to "Optimise imports".

It will take redundant or unused imports and remove them and reshuffle them etc...

I can see why it can be done... If you have 3 files A, B and C...

  1. A imports B
  2. C import A and B

In this case you can remove the import of B in C.

But what does it do to the project when these redundant imports build up? Can it slow the build? Does it affect the product?

Fogmeister
  • 70,181
  • 37
  • 189
  • 274
  • At the end of the answer : http://stackoverflow.com/a/3739563/2086502 Might help you, even if it's not complete I guess. – BoilingLime Aug 06 '15 at 14:00

1 Answers1

3

In the case of redundant imports, it's mostly to reduce code noise (i.e. unneeded lines of code). There isn't a dramatic additional cost to importing the same file twice. include does have a non-trivial cost because it has to open and read the file (even if it uses #ifdef guards), but import tries to avoid that. Even so, there's a small cost there.

Importing a file that you don't use can have a large build-time cost. In C-like languages, importing means "read the whole file and all of its included files and parse them right here." That can be very expensive. There are some tricks to avoid it being exactly that bad (particularly precompiled headers), but it's bad. So getting rid of unused imports is definitely good for build times.

Neither should have any impact on the final product. If it did, then AppCode would be removing a header it should not have removed.

Some of this changes with the new @import syntax, which doesn't require reading and parsing all the header files for modules. But you'd still want to avoid importing headers you don't need for tidiness if nothing else.

Rob Napier
  • 250,948
  • 34
  • 393
  • 528