Prefer "Before" Save-time Triggers to "After" Ones for Best Performance

When you write a trigger to derive field values programmatically, wherever possible use the Before Insert or Before Update triggers instead of After Changes Posted to Database.

When the After Changes Posted to Database trigger fires, the changes in the row have already been sent to the database, and performing further field assignments therein requires doing a second round trip to the database to permanently save your field updates to each row modified in this way. When possible, using the Before-save triggers sets the field values before the changes are sent the first time to the database, resulting in better performance.

Note: If your script utilizes the getEstimatedRowCount() function on view object query with a complex filter, then use the After Changes Posted to Database trigger for best results. The database COUNT() query the function performs to return the estimate is more accurate when performed over the already-posted data changes made during the current transaction.