Support trimming distributed transactions if unused, without a feature switch. - #3
Conversation
roji
left a comment
There was a problem hiding this comment.
@teo-tsirpanis thanks, this is really nice!
Do I understand correctly that the linker can see that s_transactionConnector will never be non-null unless ImplicitDistributedTransactions.set is called? I wasn't aware the linker could do this, is this some special allowance for static variables (since otherwise just looking at ConnectToProxy there's no context for knowing when s_transactionConnector is null etc.).
The linker sees that the This also means that if we just set |
roji
commented
Sep 30, 2022
Thanks for the explanation! But re the 2nd point, I don't think the linker can actually see that ConnectToProxy is only called when a distributed transaction is started... The fundamental API design of System.Transactions is that there's no explicit gesture for starting a distributed transaction: that's something that happens implicitly when you e.g. enlist two database connections to the same Transaction (e.g. via a TransactionScope). So I think the code wouldn't be trimmed the moment the flag is set (which is totally fine, of course). |
roji
commented
Sep 30, 2022
(In other words, if the linker could know to trim the code because no distributed transaction is started in an app, we wouldn't need the flag any more :)) |
This PR allows trimming away the distributed transactions code if the newly introduced property
TransactionManager.ImplicitDistributedTransactionsis not set. An ILLink feature switch is not needed. I also added[RequiresUnreferencedCode]to the relevant call chain, up to the aforementioned property's setter, and removed a suppression of this warning inDtcProxyShimFactory.ConnectToProxyCore.