MacOS: Annoying lag when typing
The first thing I would try is starting your iMac in Safe Mode as follows:


Fully shut down your iMac
Restart your iMac
Immediately press the Shift key and keep it down 
Let go of the Shift key when you see the login window (NOTE: If you have FileVault enabled you may need to log in twice).
Take a note of what happens (i.e. do you still notice the lag)
Exit Safe Mode by restarting your iMac as normal
Test again to see if the lag still persists


Once you've tried the above let me know if the lag was still noticeable in Safe Mode and also when booted in normally again.