title: Why is NHibernate AutoFlush check so expensive?
body: <p>In practice we are finding the default NHibernate (v2.0 &amp; 2.1) FlushMode=Auto to be extremely expensive. Reviewing the NHibernate source suggests that the algorithms for determining what needs to be flushed rely on brute-force of looping through all entities in session, and this occurs for every query run in a transaction.</p>
  
  <p>In some production scenario with updates on many items, with multiple queries we have seen the process 100 times longer with FlushMode=Auto compared to FlushMode=Commit.</p>
  
  <p>Any thoughts/advice/best practices for usage of FlushMode when performing 'complex' session logic involving multiple updates, multiple queries etc.</p>
  
  <p>Any ideas on optimizing the AutoFlush algorithms in nHibernate?</p>