How to optimize the diffie hellman key exchange algorithm

I am making a chat feature in my app where I want to encrypt it e2ee, but the problem is when I satart to calculate the public key = g^private % n. It takes a decade to get it done. I need to know to simplify it for the cpu.