How does ineffective imports affect your project?

AppCode has a "Optimize imports" feature.

This will lead to redundant or unused imports, delete them and shuffle them, etc.

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

  • Import B
  • C import A and B

In this case, you can remove import of B to C.

But what does he do with the project when these excess imports grow? Can it slow down the build? Does it affect the product?

+3


source to share


1 answer


In the case of redundant imports, it basically reduces the noise of the code (i.e. unnecessary lines of code). There is no significant additional cost to import the same file twice. include

has a nontrivial cost because it has to open and read the file (even if it uses #ifdef defenders), but import

tries to avoid it. Despite this, there is little cost.

Importing a file that you are not using can be very time consuming to build. In C-like languages, import means "read the entire file and all its included files and parse them right here." This can be very expensive. There are some tricks to avoid this being exactly that bad (especially precompiled headers), but it's bad. So getting rid of unused imports is definitely good for build times.



None of these should affect the final product. If so, then AppCode will remove the header, which it shouldn't.

Some of these changes are with new syntax @import

that does not require reading and parsing all header files for modules. But you still want to avoid importing headers that you don't need for convenience, if nothing else.

+3


source







All Articles