Many large proteins suffer from slow or inefficient folding in vitro.Here, we provide evidence that this problem can be alleviated in vivo if proteins start folding co-translationally. Using an all-atom simulation-based algorithm, we compute the folding properties of various large protein domains as a function of nascent chain length, and find that for certain proteins, there exists a narrow window of lengths that confers both thermodynamic stability and fast folding kinetics. Beyond these lengths, folding is drastically slowed by non-native interactions involving C-terminal residues. Thus, cotranslational folding is predicted to be beneficial because it allows proteins to take advantage of this optimal window of lengths and thus avoid kinetic traps. Interestingly, many of these proteins' sequences contain conserved rare codons that may slow down synthesis at this optimal window, suggesting that synthesis rates may be evolutionarily tuned to optimize folding. Using kinetic modelling, we show that under certain conditions, such a slowdown indeed improves co-translational folding efficiency by giving these nascent chains more time to fold. In contrast, other proteins are predicted not to benefit from co-translational folding due to a lack of significant non-native interactions, and indeed these proteins' sequences lack conserved C-terminal rare codons. Together, these results shed light on the factors that promote proper protein folding in the cell, and how biomolecular self-assembly may be optimized evolutionarily.