paulirwin commented on code in PR #938:
URL: https://github.com/apache/lucenenet/pull/938#discussion_r1713836719


##########
src/Lucene.Net/Support/ConcurrentHashSet.cs:
##########
@@ -74,9 +74,9 @@ public int Count
                 {
                     AcquireAllLocks(ref acquiredLocks);
 
-                    for (var i = 0; i < _tables.CountPerLock.Length; i++)
+                    foreach (var t in _tables.CountPerLock)

Review Comment:
   There was a Stephen Toub video recently where he was showing how you 
shouldn't prematurely optimize things like this, because the compiler can 
sometimes come up with something even faster.
   
   I wrote a small benchmark and strictly for summing over an int array, 
foreach is faster, and LINQ `Sum()` is even faster:
   ```
   |-------- |---------:|---------:|---------:|---------:|
   | ForEach | 68.36 ns | 1.377 ns | 2.750 ns | 67.69 ns |
   | For     | 89.54 ns | 1.820 ns | 3.956 ns | 89.10 ns |
   | LinqSum | 50.46 ns | 1.322 ns | 3.878 ns | 48.67 ns |
   ```
   
   I could do the LINQ Sum here, but let me know if you're good with this for 
now.
    



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to