Keyboard lag, especially when other users are logged in
I have an administrator account on my MacBook Pro. Lately I have problems with sluggish keyboard input. I'll be typing normally and the output on the screen will lag for 100-500ms and then catch up all at once. This happens several times per minute, and sometimes every few seconds, so it's very annoying.
I notice it the most in Google Chrome, but I think that's just because I spend most time there. I think it also happens in apps such as iTerm2.
Occasionally other users log in to my MacBook as well when I'm not using it, and their accounts stay logged in (but inactive) when I'm using it. I think this problem happens most often when those other users are logged in as well, or when the computer has been on for a long time. Restarting always fixes it temporarily.
I've checked that there are no heavy processes running in the background. CPU, memory, and other resources are hardly being used at all.
What's going on here?
MacBook Pro 15”, macOS 10.15