Reduce contention and unnecessary checks at each lookup, part of xambug #14644.
authorPaolo Molaro <lupus@oddwiz.org>
Tue, 5 Nov 2013 16:37:08 +0000 (17:37 +0100)
committerPaolo Molaro <lupus@oddwiz.org>
Tue, 5 Nov 2013 16:37:08 +0000 (17:37 +0100)
mcs/class/System/System.Net/ServicePointManager.cs

index a6d456293e63c54d739ab11e50275875d419bab1..27e9893a80a86df8f2db606cb13f126378cf62d2 100644 (file)
@@ -326,7 +326,8 @@ namespace System.Net
                        if (address == null)
                                throw new ArgumentNullException ("address");
 
-                       RecycleServicePoints ();
+                       if ((servicePoints.Count % 4) == 0)
+                               RecycleServicePoints ();
 
                        var origAddress = new Uri (address.Scheme + "://" + address.Authority);
                        
@@ -346,8 +347,8 @@ namespace System.Net
                        address = new Uri (address.Scheme + "://" + address.Authority);
                        
                        ServicePoint sp = null;
+                       SPKey key = new SPKey (origAddress, usesProxy ? address : null, useConnect);
                        lock (servicePoints) {
-                               SPKey key = new SPKey (origAddress, usesProxy ? address : null, useConnect);
                                sp = servicePoints [key] as ServicePoint;
                                if (sp != null)
                                        return sp;