Zach's answer will not work with subdomains like forum.example.com, the next rules checks whether the host equals example.com. If it does, it will be redirected to www.example.com. No rules will be processed after this one (L = Last).
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
This does not cause a server slowdown, but if you really want to get every single performance bit out of it, you could create a virtual host with domain example.com with a redirect rule:
NameVirtualHost 1.2.3.4:80
<VirtualHost 1.2.3.4:80>
ServerName example.com
Redirect / http://www.example.com/
</VirtualHost>
# other hosts here
Virtual Hosts documentation