Add a shortcut to reduce Transaction.Current reads #2213
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since some users complain of a reduction performance with transactions and NHibernate v5.x, I have a look in which changes may have an impact. See here and here for the reports on performance losses.
In v4.x and previous versions, there was a shortcut avoiding to read
Transaction.Current
when the session was already having a transaction context.So I have made a bench for comparing accessing the session transaction context vs the current transaction. The later is around twenty times slower on my setup.
As a consequence I propose re-adding that shortcut.
(Still the first thread states the negative impact occurs also with regular transactions, while upgrading from NHv3.3. But with regular transactions, there is never a transaction context on the session, so the shortcut is not taken, and the current transaction is read. And in v3.3, the default transaction factory was already the system transaction one. The only explanation I could have would be that the performance of reading the current transaction itself has also dropped with .Net Framework v4, those old projects upgrades having probably also upgraded from an old framework.)