This feature “Perform Synchronous Compile on Deploy in Salesforce” is enabled automatically for production orgs but it’s an opt-in feature for sandboxes.
Previously, installation and upgrades with large packages resulted in all classes not being compiled. This causes serious app performance issues until all classes are compiled.
Each org’s Apex code is now automatically recompiled before completing a metadata deploy, package install, or package upgrade. This change in behavior improves performance following metadata deploys and package updates. Previously, a deploy, install, or upgrade could leave an org with invalidated code, causing reduced performance while Apex was recompiled.
This feature causes deployments to the org to invoke the Apex compiler and save the resulting bytecode as part of the deployment. A minimal increase in deployment times can occur, but Apex doesn’t need to be recompiled on first run. So the slight increase in deployment time can prevent performance issues on first run.
1) Go to Setup –> Apex Settings.
2) Enable “Perform Synchronous Compile on Deploy”