The Galaxy S4 really is an amazing smartphone with some pretty amazing specifications, as powerful this phone is with 2 gigs of RAM and either a quad-core 1.9ghz Snapdragon 600 CPU or the 1.6ghz Exynos 5 Octa CPU the phone still suffers from lag issues. This is because of Touchwiz mainly, Samsung's skin comes with tons of features that we could spend all day discussing but we wont and it is very resource heavy on the phone. With all of the enhancements and software features, the phone's internal storage is limited and many of these features run simultaneously whether or not if your using them. The phone has 2 gigs of RAM which should help its performance but in this case its not enough as often the user is left with less than 500mb of free RAM due to all of the various features and preloaded programs that run in the background.
A good way to reduce the lag and increase the performance of your device is to go into the developer options and limit the number of background processes the CPU can handle at any time. This works on not only the Galaxy S4 but most other Samsung Galaxy devices with the exception of some older models like the Galaxy S.
To change the background processes count you need to access the developer options menu in the settings which may vary based on device. The Galaxy S4 has a pretty crazy way of accessing the developer options by taping on the device's Android build number multiple times in the about phone section. Most other devices have a section dedicated to developer options in the settings menu.
Below is a screen cap from the Galaxy Note 10.1 showing the developer options section in the settings menu
Once in developer options, scroll down the Apps tab and select Limit Background processes and change the value from standard limit to 4 at most.
Clicking on Limit background processes brings up a dialog box where you can change the values, select 4 processes at most as this is probably the best setting.
After changing the background processes limit, you should notice a significant improvement in the device's performance. On the Galaxy S4, this reduces lag and even fixes the camera bug where clicking on the camera application in some cases can cause the device to malfunction and reboot itself. RAM consumption is also reduced as there are fewer programs running in the background.
RAM consumption with no limit on background processes, no apps are running
RAM consumption after changing the limit on background processes to 4
As you can see with no applications running and the limit changed to 4, the amount of RAM being consumed by the system was reduced by more than 10 megabites. That might not seem like much but it does make a difference when you are using applications.
As helpful as this is, I should note that these settings when you change them are not permanent, when you restart the device it goes back to the default setting of no limit. So you will have to change it again.