Rooting simply means that you are allowed to access the base directory where android is installed, sort of like getting access to the windows or program files folder on your computer.
Lagging, as you call it, is simply when the tasks that you are using are not getting enough resources (processor time/ram etc). This is mostly a software issue. The Samsung touchwiz interface is a huge memory hog and Samsung keeps adding more and more bloatware to it. this is pretty evident from the fact that the install size of the stock android + touchwiz of the galaxy S3 is around 1.1 GB whereas cyanogenmod 11 is around 190 MB. Most of these bloatware services will run in the background and eat up memory/processor which will cause the phone to slow down. Also some apps like the samsung dialer, samsung SMS app are horribly made, it used to take me upto 10 sec to open the dialer and actually dial a number. Most of this will be solved if you move to a custom ROM
Viruses and malware is an entirely different problem and a simple factory reset should fix this if this is the only issue you want to solve.