msfroh commented on code in PR #12995: URL: https://github.com/apache/lucene/pull/12995#discussion_r1444073439
########## lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/TaxonomyIndexArrays.java: ########## @@ -38,27 +38,49 @@ * @lucene.experimental */ class TaxonomyIndexArrays extends ParallelTaxonomyArrays implements Accountable { + private static final int CHUNK_SIZE = 8192; - private final int[] parents; + private final ChunkedArray parents; // the following two arrays are lazily initialized. note that we only keep a // single boolean member as volatile, instead of declaring the arrays // volatile. the code guarantees that only after the boolean is set to true, // the arrays are returned. private volatile boolean initializedChildren = false; - private int[] children, siblings; + private ChunkedArray children, siblings; + + private static class ChunkedArray extends ParallelTaxonomyArrays.IntArray { + private final int[][] values; + + private ChunkedArray(int[][] values) { + this.values = values; + } + + @Override + public int get(int i) { + return values[i / CHUNK_SIZE][i % CHUNK_SIZE]; + } + + public void set(int i, int val) { + values[i / CHUNK_SIZE][i % CHUNK_SIZE] = val; + } + + @Override + public int length() { + return (values.length - 1) * CHUNK_SIZE + values[values.length - 1].length; + } + } /** Used by {@link #add(int, int)} after the array grew. */ - private TaxonomyIndexArrays(int[] parents) { - this.parents = parents; + private TaxonomyIndexArrays(int[][] parents) { + this.parents = new ChunkedArray(parents); } public TaxonomyIndexArrays(IndexReader reader) throws IOException { - parents = new int[reader.maxDoc()]; - if (parents.length > 0) { - initParents(reader, 0); - parents[0] = TaxonomyReader.INVALID_ORDINAL; - } + int[][] parentArray = allocateChunkedArray(reader.maxDoc()); Review Comment: I was a little torn on this. I figured I would try to avoid method calls where possible (assuming method calls have more overhead than array access), and could happily muck about in the `ChunkedArray` internals within `TaxonomyIndexArrays`(since it's a private implementation detail). We could move `allocateChunkedArray` and `copyChunkedArray` logic into `ChunkedArray` itself (and call them from `ChunkedArray` constructors). It's still in the same file, so I don't have strong opinions either way. -- 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. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org