Should I instead
import DequeModule
and import other things when I use those?
Should I instead
import DequeModule
and import other things when I use those?
Swift can do dead code elimination but it can be hit-and-miss. Itās better to import specifically and only what you use.
As @lukasa said, Swift tries to eliminate what you havenāt touched, at least in release builds. So in general the difference is more significant in the manifest where you select which products you need. If you depend on products you arenāt going to use, you can end up with more transitive dependency version constraints than really matter, and that makes it more likely to run into constraints that are mutually exclusive some other package. You also waste time during development each time you fetch or build the unneeded dependencies.
For quick experiments or beginnerālevel examples you provide in documentation, it tends to be better to depend and import broadly simply because it is less work to get something up and running. But on real projects it is almost always better to depend and import narrowly for the reasons mentioned above.
What happens if you import specifically the Deque
struct?
import struct Collections.Deque
It makes no difference: