dweiss commented on a change in pull request #1416: LUCENE-9286: FST.Arc.BitTable is read directly from the FST bytes. URL: https://github.com/apache/lucene-solr/pull/1416#discussion_r405681455
########## File path: lucene/core/src/java/org/apache/lucene/util/fst/BitTableUtil.java ########## @@ -0,0 +1,200 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.lucene.util.fst; + +import java.io.IOException; + +/** + * Static helper methods for {@link FST.Arc.BitTable}. + * + * @lucene.experimental + */ +class BitTableUtil { + + /** + * Returns whether the bit at given zero-based index is set. + * <br>Example: bitIndex 10 means the third bit on the right of the second byte. + * + * @param bitIndex The bit zero-based index. It must be greater than or equal to 0, and strictly less than + * {@code number of bit-table bytes * Byte.SIZE}. + * @param reader The {@link FST.BytesReader} to read. It must be positioned at the beginning of the bit-table. + */ + static boolean isBitSet(int bitIndex, FST.BytesReader reader) throws IOException { + assert bitIndex >= 0 : "bitIndex=" + bitIndex; + reader.skipBytes(bitIndex >> 3); + return (readByte(reader) & (1L << (bitIndex & (Byte.SIZE - 1)))) != 0; + } + + + /** + * Counts all bits set in the bit-table. + * + * @param bitTableBytes The number of bytes in the bit-table. + * @param reader The {@link FST.BytesReader} to read. It must be positioned at the beginning of the bit-table. + */ + static int countBits(int bitTableBytes, FST.BytesReader reader) throws IOException { + assert bitTableBytes >= 0 : "bitTableBytes=" + bitTableBytes; Review comment: I noticed the byte order difference (note the "for bitcounts" bit). :) My gut feeling is that pushing reads so that they're aggregated first, followed by a bitcount will still give you a performance improvement. A bit shift and a bit mask is probably dwarfed when hotspot compiles and inlines all this but single-byte get() methods with conditionals inside will typically perform worse than a bulk get. This is a scholarly discussion as things will very likely vary from machine to machine and even between hotpot runs, depending on the calling code layout. ---------------------------------------------------------------- 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