lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eladmarg <...@git.apache.org>
Subject [GitHub] lucenenet pull request #188: Fixed 64 Failing Facet Tests and Finished Facet...
Date Wed, 28 Sep 2016 20:33:08 GMT
Github user eladmarg commented on a diff in the pull request:

    https://github.com/apache/lucenenet/pull/188#discussion_r81009940
  
    --- Diff: src/Lucene.Net.Facet/Taxonomy/LRUHashMap.cs ---
    @@ -100,19 +120,25 @@ public bool Put(TKey key, TValue value)
                             timestamp = GetTimestamp()
                         };
                         // We have added a new item, so we may need to remove the eldest
    -                    if (cache.Count > Capacity)
    +                    if (cache.Count > capacity)
                         {
                             // Remove the eldest item (lowest timestamp) from the cache
                             cache.Remove(cache.OrderBy(x => x.Value.timestamp).First().Key);
                         }
                     }
    +
    +                return true;
    +            }
    +            finally
    +            {
    +                syncLock.ExitWriteLock();
                 }
    -            return true;
             }
     
             public TValue Get(TKey key)
             {
    -            lock (syncLock)
    +            syncLock.EnterWriteLock();
    --- End diff --
    
    I'm not sure if it's worth the pay of price of thread safe here,
    Generally, the main purpose of LRUCache is to delete the old entries, we want to store
~10K items, we don't really care if we removed the ones that has been used 2 ticks later.

    so the order is nice to have but not a must, this is a cache so the main goal is performance.
    here is mine implementation, you can take a look.
    https://gist.github.com/eladmarg/8d4a7f7a43a36c35d488e99475a101d9
    
    yes, there is a chance that the Lru tests will fail, but we shouldn't care.
    
    this is of course just a recommendation, we should get the version out and then think
about performance.
    Thank You!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message