All functions used should be well optimized for performance, we are talking about dovecot here. More info: https://doc.dovecot.org/configuration_manual/performance_tuning/
Postfix: https://www.postfix.org/TUNING_README.html