From f5b5afba04509fb99bf9cf9509704f1ee3334a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=C4=B5=20=CE=9D=CE=B9=CE=93=CE=9E=CE=97=CE=9B=CF=88?= =?UTF-8?q?=CE=9A?= Date: Mon, 28 Jun 2021 10:51:24 +0530 Subject: [PATCH] micro optimizations --- MongoDB.Entities/Commands/Update.cs | 4 ++-- MongoDB.Entities/Commands/UpdateAndGet.cs | 4 ++-- MongoDB.Entities/Core/Watcher.cs | 2 +- MongoDB.Entities/MongoDB.Entities.csproj | 5 +++-- MongoDB.Entities/Relationships/Many.Add.cs | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/MongoDB.Entities/Commands/Update.cs b/MongoDB.Entities/Commands/Update.cs index 30095a537..dd6613a58 100644 --- a/MongoDB.Entities/Commands/Update.cs +++ b/MongoDB.Entities/Commands/Update.cs @@ -315,8 +315,8 @@ public Update WithArrayFilter(string filter) options.ArrayFilters = options.ArrayFilters == null - ? new List() { def } - : options.ArrayFilters.Concat(new List { def }); + ? new[] { def } + : options.ArrayFilters.Concat(new[] { def }); return this; } diff --git a/MongoDB.Entities/Commands/UpdateAndGet.cs b/MongoDB.Entities/Commands/UpdateAndGet.cs index a0aae1746..6457607e9 100644 --- a/MongoDB.Entities/Commands/UpdateAndGet.cs +++ b/MongoDB.Entities/Commands/UpdateAndGet.cs @@ -283,8 +283,8 @@ public UpdateAndGet WithArrayFilter(string filter) options.ArrayFilters = options.ArrayFilters == null - ? new List() { def } - : options.ArrayFilters.Concat(new List { def }); + ? new[] { def } + : options.ArrayFilters.Concat(new[] { def }); return this; } diff --git a/MongoDB.Entities/Core/Watcher.cs b/MongoDB.Entities/Core/Watcher.cs index d90308566..eb91e54bd 100644 --- a/MongoDB.Entities/Core/Watcher.cs +++ b/MongoDB.Entities/Core/Watcher.cs @@ -141,7 +141,7 @@ private void Init( resume = autoResume; cancelToken = cancellation; - var ops = new List() { ChangeStreamOperationType.Invalidate }; + var ops = new List(3) { ChangeStreamOperationType.Invalidate }; if ((eventTypes & EventType.Created) != 0) ops.Add(ChangeStreamOperationType.Insert); diff --git a/MongoDB.Entities/MongoDB.Entities.csproj b/MongoDB.Entities/MongoDB.Entities.csproj index ebdbdd3dd..59d2a41bb 100644 --- a/MongoDB.Entities/MongoDB.Entities.csproj +++ b/MongoDB.Entities/MongoDB.Entities.csproj @@ -8,13 +8,14 @@ A data access library for MongoDB with an elegant api, LINQ support and built-in entity relationship management. LICENSE https://mongodb-entities.com - 20.16.0-beta4 + 20.16.0-beta5 Đĵ ΝιΓΞΗΛψΚ - added DB.InsertAsync() method - added method for deleting join collections - optimized internal performance by using lists instead of hashsets - optimized Cache<T> class -- optimized Watcher class +- optimized Watcher class +- various other minor performance optimizations MongoDB.Entities MongoDB.Entities https://github.com/dj-nitehawk/MongoDB.Entities diff --git a/MongoDB.Entities/Relationships/Many.Add.cs b/MongoDB.Entities/Relationships/Many.Add.cs index 85456eac3..8f36cfdc9 100644 --- a/MongoDB.Entities/Relationships/Many.Add.cs +++ b/MongoDB.Entities/Relationships/Many.Add.cs @@ -55,7 +55,7 @@ public Task AddAsync(IEnumerable childIDs, IClientSessionHandle session { parent.ThrowIfUnsaved(); - var models = new List>(); + var models = new List>(childIDs.Count()); foreach (var cid in childIDs) { cid.ThrowIfUnsaved();