There is not a fixed set of factors, but one could be the one you listed, the need for economizing, which by the way is always strong and present regardless of the language. Languages always tend to say more with less effort and waste of energies (or sounds).
Another factor, which I think is very prominent, is the lack (temporary or not) of competencies in the other language.
What do I mean by this? If you're speaking one language and you just don't have the necessary competencies to say something (high register, specialized terminology, etc), you'll switch to the other one. This would happen if you knew that the other person has the same abilities that you do.
Code-switching happens in a community or in a group of people that share at least two languages (usually code-switching supposes the presence of bilingualism, or at least fluency in two languages from both speakers; it's related to Linguistic interference), so you know subconsciously that the other person can speak the other language, otherwise you wouldn't switch. If you have the competencies but you feel a sudden loss of words, you'll switch, maybe just for that sentence/expression.
Yet another factor, perhaps not applicable in your case but still worth to mention, is identity. For example, you speak a dialect with your family only and the official language of your country with the rest. One of your relatives moves away and they start speaking the official language more and the dialect less for various reasons. If you talk to them then, some code-switching might occur, because you sometimes use the dialect (being family) and other times switch to the main language (because maybe they keep using that one); they might do code-switching too, of course.