From 65270f3717054c92d38f2e790b94b1be3768b83f Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Wed, 13 Feb 2019 21:55:46 -0500 Subject: [PATCH] Avoid syncobj object allocation in Http2Connection Just use one of the other readonly objects. Commit migrated from https://github.com/dotnet/corefx/commit/d74108c671abffa3d314b011b7269806eedb7df7 --- .../Net/Http/SocketsHttpHandler/Http2Connection.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs index e75fe1a..fd309f4 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs @@ -20,7 +20,6 @@ namespace System.Net.Http { private readonly HttpConnectionPool _pool; private readonly SslStream _stream; - private readonly object _syncObject; // NOTE: These are mutable structs; do not make these readonly. private ArrayBuffer _incomingBuffer; @@ -61,7 +60,6 @@ namespace System.Net.Http { _pool = pool; _stream = stream; - _syncObject = new object(); _incomingBuffer = new ArrayBuffer(InitialConnectionBufferSize); _outgoingBuffer = new ArrayBuffer(InitialConnectionBufferSize); _headerBuffer = new ArrayBuffer(InitialConnectionBufferSize); @@ -79,6 +77,8 @@ namespace System.Net.Http _maxConcurrentStreams = int.MaxValue; } + private object SyncObject => _httpStreams; + public async Task SetupAsync() { _outgoingBuffer.EnsureAvailableSpace(s_http2ConnectionPreface.Length + @@ -247,7 +247,7 @@ namespace System.Net.Http throw new Http2ProtocolException(Http2ProtocolErrorCode.ProtocolError); } - lock (_syncObject) + lock (SyncObject) { if (!_httpStreams.TryGetValue(streamId, out Http2Stream http2Stream)) { @@ -461,7 +461,7 @@ namespace System.Net.Http { Debug.Assert(newSize >= 0); - lock (_syncObject) + lock (SyncObject) { int delta = newSize - _initialWindowSize; _initialWindowSize = newSize; @@ -981,7 +981,7 @@ namespace System.Net.Http private void AbortStreams(int lastValidStream) { - lock (_syncObject) + lock (SyncObject) { if (!_disposed) { @@ -1010,7 +1010,7 @@ namespace System.Net.Http private void CheckForShutdown() { Debug.Assert(_disposed); - Debug.Assert(Monitor.IsEntered(_syncObject)); + Debug.Assert(Monitor.IsEntered(SyncObject)); // Check if dictionary has become empty if (_httpStreams.Count != 0) @@ -1028,7 +1028,7 @@ namespace System.Net.Http public void Dispose() { - lock (_syncObject) + lock (SyncObject) { if (!_disposed) { @@ -1192,7 +1192,7 @@ namespace System.Net.Http private Http2Stream AddStream(HttpRequestMessage request) { - lock (_syncObject) + lock (SyncObject) { if (_disposed || _nextStream == MaxStreamId) { @@ -1216,7 +1216,7 @@ namespace System.Net.Http private void RemoveStream(Http2Stream http2Stream) { - lock (_syncObject) + lock (SyncObject) { if (!_httpStreams.Remove(http2Stream.StreamId, out Http2Stream removed)) { -- 2.7.4