magibney commented on a change in pull request #2:
URL: https://github.com/apache/solr/pull/2#discussion_r593320574
##########
File path: solr/core/src/java/org/apache/solr/search/BitDocSet.java
##########
@@ -237,6 +237,150 @@ public BitDocSet clone() {
return new BitDocSet(bits.clone(), size);
}
+ @Override
+ public Bits getBits(LeafReaderContext context) {
+ if (context.isTopLevel) {
+ return bits;
+ }
+
+ final int base = context.docBase;
+ final int length = context.reader().maxDoc();
+ final FixedBitSet bs = bits;
+
+ return new Bits() {
+ @Override
+ public boolean get(int index) {
+ return bs.get(index + base);
+ }
+
+ @Override
+ public int length() {
+ return length;
+ }
+ };
+ }
+
+ private static final int NO_DOCS_THIS_SEGMENT = -1;
+ private int[] cachedFloorDocs;
Review comment:
fwiw, I did intend this code to be (and am pretty sure it is)
thread-safe. Because `cachedFloorDocs` is privately built in its entirety by a
calling thread and set atomically, the worst-case scenario is that multiple
threads end up building the same array, and the array that ends up being cached
is arbitrary.
Analogous to `cachedOrdIdxMap` in `SortedIntDocSet`, there are four options:
1. accumulate the relevant information during collection and supply it as an
arg to the ctor (feasible? given the different ways in which DocSets might be
built?)
2. eagerly compute the relevant information in the ctor (unnecessary work
for DocSets that are only used at the global level -- i.e., never need to
supply a per-segment iterator)
3. compute (and cache) the relevant information on-demand the first time
`DocSet.iterator(LeafReaderContext)` is called
A fourth option (for `BitDocSet` anyway) is "do nothing", but given that
DocSets are cached, and the optimization of returning `null` instead of empty
iterators can be valuable to consumers, I do think it's worth the extra effort
to do _something_ here ...
----------------------------------------------------------------
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:
[email protected]