Skip to content

Commit

Permalink
Disable the query cache by default.
Browse files Browse the repository at this point in the history
The query cache trades heap for faster queries. Given all the progress
that has been made on making uncached queries faster
(`IndexOrDocValuesQuery`, bitset encoding of blocks of postings, etc.),
it's not obviously a good trade-off anymore. So I suggest that we make
it an opt-in in Lucene 11.
  • Loading branch information
jpountz committed Jan 30, 2025
1 parent faec0f8 commit 0c95a7f
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
public class IndexSearcher {

static int maxClauseCount = 1024;
private static QueryCache DEFAULT_QUERY_CACHE;
// Caching is disabled by default.
private static QueryCache DEFAULT_QUERY_CACHE = null;
private static QueryCachingPolicy DEFAULT_CACHING_POLICY = new UsageTrackingQueryCachingPolicy();
private QueryTimeout queryTimeout = null;
// partialResult may be set on one of the threads of the executor. It may be correct to not make
Expand All @@ -86,13 +87,6 @@ public class IndexSearcher {
// shouldn't hurt either.
private volatile boolean partialResult = false;

static {
final int maxCachedQueries = 1000;
// min of 32MB or 5% of the heap size
final long maxRamBytesUsed = Math.min(1L << 25, Runtime.getRuntime().maxMemory() / 20);
DEFAULT_QUERY_CACHE = new LRUQueryCache(maxCachedQueries, maxRamBytesUsed);
}

/**
* By default, we count hits accurately up to 1000. This makes sure that we don't spend most time
* on computing hit counts
Expand Down

0 comments on commit 0c95a7f

Please sign in to comment.