Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider removing unnecessary reference copies in prologues to closures in AutorecoveringConnection #517

Closed
antiduh opened this issue Feb 12, 2019 · 1 comment

Comments

@antiduh
Copy link

antiduh commented Feb 12, 2019

Before forming a closure, a couple bits of code in AutorecoveringConnection save off a second copy of the this pointer:

       public void BeginAutomaticRecovery()
        {
            lock (recoveryLockTarget)
            {
                if (!performingRecovery)
                {
                    performingRecovery = true;
>>>             var self = this;

                    recoveryTaskFactory.StartNew(() =>
                    {
                        if (!self.ManuallyClosed)
                        {
                            try
                            {
#if NETFX_CORE
                                System.Threading.Tasks.Task.Delay(m_factory.NetworkRecoveryInterval).Wait();
#else
                                Thread.Sleep(m_factory.NetworkRecoveryInterval);
#endif
                                self.PerformAutomaticRecovery();

And:

        private void Init(IFrameHandler fh)
        {
            m_delegate = new Connection(m_factory, false,
                fh, this.ClientProvidedName);

>>>     AutorecoveringConnection self = this;
            EventHandler<ShutdownEventArgs> recoveryListener = (_, args) =>
            {
                lock (recoveryLockTarget)
                {
                    if (ShouldTriggerConnectionRecovery(args))
                    {
                        try
                        {
                            self.BeginAutomaticRecovery();

I don't believe these copies serve any purpose.

@michaelklishin
Copy link
Member

I am responsible for connection recovery in most clients and have a theory :) This was a more or less literate port of the Java client implementation, and a final this reference is required there. Feel free to submit a PR that does away with them 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants