So, let us say that we have set-up an A record and an AAAA record for @, and for www we have set-up a CNAME pointing to @.
When a new visitor visits example.com and the webserver sends a 301 permanent redirect to www.example.com, will that still require an extra DNS lookup after the CNAME, even though it already knows @'s location?
If so, why do many companies use the CNAME method over an additional A and AAAA for www?
Finally I would like to mention that I have searched through the whole internet for an answer to this question.
If you have many subdomains pointing to one server, it's easier to manage, since you only need to change one A record when the servers IP changes, and the CNAMES will all point to the new IP - no need to setup every alias' IP separately.
Otherwise, it's pretty much your choice which method you use.
To answer your initial question, when a CNAME is used to point www.@ in a zone, the initial CNAME lookup is performed, followed by a second lookup for the A record indicated by the CNAME. If the client has not accessed this before, typically this response will be cached and any further lookups of this A record within the TTL of the record looked up will be responded to from the cache.
Many companies use CNAME records where they have multiple subdomains of their main domain pointed to the same server. As above (response by mulaz), when the server IP or location changes, only one record needs to update, rather than a few hundred (which may be the case) saving both time, and making configuration easier.
In your case of www CNAMEd to @ of the same domain, extra lookup is never necessary. Authoritative server, when asked for a www, will send both - CNAME record, and A record(s) of a CNAME target (@ in your case). The same true for any CNAME which points to another hostname within the same zone.
Extra lookup will be necessary only if CNAME points to another domain.
CNAME used because it's easier to manage - when address changes, it needs to be changed only only for one hostname.
IMHO, technically, it's not strictly correct to point CNAMEs to @, as @ usually contains additional records, such as MX for instance. If you CNAME www to @, you mean A record, but all those other records will appear as existing for www as well. Thus someone may think that he can send an email to [email protected], for instance.