DisclaimerDisclosure: I work for an anti-virus vendor.
Because most anti-virus engines were born as protecting endpoints, and even now for many of them endpoint protection is major part of business, the modern anti-virus engines are optimized for scanning endpoints. This optimization includes many things, such as:
Not scanning the files which couldn't contain infections which can infect your computer;
Remembering which files were scanned, and not scanning them again unless the files were modified;
Optimizing scans for the file types when possible - for example when scanning executables, only certain parts of it need to be scanned. This minimizes disk reads, and improves performance.
A common misconception is that AV engines use hashes. They generally do not, for three reasons:
- First is that getting around hash detection is very easy and doesn't require modifying the actual malicious code at all;
- Second is that using hashes does not allow you to implement any kind of proactive protection - you will only be able to detect malware which you have seen;
- Calculating a hash requires the whole file to be read, while for some files (such as executables) this is not necessary. And reading the whole file on non-SSD hard drives is expensive operation - most AV engines should scan a large clean executable file faster than calculating hash on it