jpountz commented on a change in pull request #940: LUCENE-9002: Query caching 
leads to absurdly slow queries
URL: https://github.com/apache/lucene-solr/pull/940#discussion_r334009994
 
 

 ##########
 File path: lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java
 ##########
 @@ -732,8 +741,39 @@ public ScorerSupplier scorerSupplier(LeafReaderContext 
context) throws IOExcepti
 
       if (docIdSet == null) {
         if (policy.shouldCache(in.getQuery())) {
-          docIdSet = cache(context);
-          putIfAbsent(in.getQuery(), docIdSet, cacheHelper);
+          final ScorerSupplier supplier = in.scorerSupplier(context);
+          if (supplier == null) {
+            putIfAbsent(in.getQuery(), DocIdSet.EMPTY, cacheHelper);
+            return null;
+          }
+
+          final long cost = supplier.cost();
+          return new ScorerSupplier() {
+            @Override
+            public Scorer get(long leadCost) throws IOException {
+              // skip cache operation which would slow query down too much
+              if ((cost > skipCacheCost || cost > leadCost * skipCacheFactor)
 
 Review comment:
   > control the time used for caching as the caching time is related to the 
cost of range query
   
   Understood, but if the query has a 250x higher cost already, then it's 
probably fine right?
   
   > skip caching too large range queries which will consume too much memory 
and evict cache entries frequently
   
   Maybe a more intuitive way to do that would be to call this parameter 
`maxRamBytesUsedPerEntry` and skip caching if `min(maxDoc/Byte.SIZE /* assuming 
bitset */, cost * Short.BYTES /* assuming short[] */) > 
maxRamBytesUsedPerEntry`?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to