Performance improvement - only write to session if necessary instead of on every request.