From bb860e87660e1ee46e3849f2955210d2da97ad0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schr=C3=B6dinger=27s=20Cat?= Date: Tue, 20 Nov 2018 19:34:33 +0100 Subject: [PATCH 1/2] Improve performance of SendMessageToClient() calls +The null/empty check for the set property checks the current value (which is always null). It should check the value to be assigned instead. +This also reduces GC (89KB) and CPU (8%) (reported by Unity Profiler on i7-3770) --- src/OSC/OSCPacket.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OSC/OSCPacket.cs b/src/OSC/OSCPacket.cs index aa33d03..4e8922b 100644 --- a/src/OSC/OSCPacket.cs +++ b/src/OSC/OSCPacket.cs @@ -48,7 +48,7 @@ public string Address } set { - Trace.Assert(string.IsNullOrEmpty(_address) == false); + Trace.Assert(string.IsNullOrEmpty(value) == false); _address = value; } } From 7a4f573d0262851194a560b1356c0399482f297f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schr=C3=B6dinger=27s=20Cat?= Date: Wed, 21 Nov 2018 14:42:41 +0100 Subject: [PATCH 2/2] Check if client already exists so it can't be added twice --- src/OSCHandler.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/OSCHandler.cs b/src/OSCHandler.cs index e4cb3ce..9b4a24c 100644 --- a/src/OSCHandler.cs +++ b/src/OSCHandler.cs @@ -157,6 +157,9 @@ void OnApplicationQuit() /// public void CreateClient(string clientId, IPAddress destination, int port) { + if (_clients.ContainsKey(clientId)) { + return; + } ClientLog clientitem = new ClientLog(); clientitem.client = new OSCClient(destination, port); clientitem.log = new List();