-
Notifications
You must be signed in to change notification settings - Fork 1.6k
GH-3772: Bulk skip in RunLengthBitPackingHybridDecoder / DictionaryValuesReader #3773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abstractdog
wants to merge
1
commit into
apache:master
Choose a base branch
from
abstractdog:probe-decode-support-parquet-java
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
136 changes: 136 additions & 0 deletions
136
parquet-benchmarks/src/main/java/org/apache/parquet/benchmarks/RleSkipBenchmark.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| /* | ||
| * 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.parquet.benchmarks; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.Random; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.apache.parquet.bytes.ByteBufferInputStream; | ||
| import org.apache.parquet.bytes.DirectByteBufferAllocator; | ||
| import org.apache.parquet.column.values.rle.RunLengthBitPackingHybridDecoder; | ||
| import org.apache.parquet.column.values.rle.RunLengthBitPackingHybridEncoder; | ||
| import org.openjdk.jmh.annotations.Benchmark; | ||
| import org.openjdk.jmh.annotations.BenchmarkMode; | ||
| import org.openjdk.jmh.annotations.Fork; | ||
| import org.openjdk.jmh.annotations.Level; | ||
| import org.openjdk.jmh.annotations.Measurement; | ||
| import org.openjdk.jmh.annotations.Mode; | ||
| import org.openjdk.jmh.annotations.OperationsPerInvocation; | ||
| import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
| import org.openjdk.jmh.annotations.Param; | ||
| import org.openjdk.jmh.annotations.Scope; | ||
| import org.openjdk.jmh.annotations.Setup; | ||
| import org.openjdk.jmh.annotations.State; | ||
| import org.openjdk.jmh.annotations.Warmup; | ||
|
|
||
| /** | ||
| * Measures {@link RunLengthBitPackingHybridDecoder#skipInts(int)} vs. the equivalent | ||
| * discard-via-readInt loop. Both paths decode each run the same way; the win comes from | ||
| * dropping the per-value mode-switch, array-index arithmetic and method-call overhead of | ||
| * {@code readInt()} in favour of a single {@code currentCount -= consume} per run. | ||
| * | ||
| * <p>Parameters: | ||
| * <ul> | ||
| * <li>{@link #bitWidth} -- key width, chosen at 3/8/16 to bracket typical dictionary-index | ||
| * widths.</li> | ||
| * <li>{@link #pattern} -- {@code rle} produces long runs of a single value (best case for both | ||
| * paths); {@code packed} produces mostly distinct values so the encoder emits bit-packed | ||
| * groups (worst case for the old skip); {@code mixed} interleaves the two.</li> | ||
| * </ul> | ||
| * | ||
| * Each invocation re-wraps a pre-encoded byte buffer and calls {@code skipInts(VALUE_COUNT)} in | ||
| * the {@code skip} benchmark, versus a {@code VALUE_COUNT}-long {@code readInt()} discard loop | ||
| * in the {@code readSkip} benchmark. | ||
| */ | ||
| @BenchmarkMode(Mode.Throughput) | ||
| @OutputTimeUnit(TimeUnit.SECONDS) | ||
| @Fork(1) | ||
| @Warmup(iterations = 3, time = 1) | ||
| @Measurement(iterations = 5, time = 1) | ||
| @State(Scope.Thread) | ||
| public class RleSkipBenchmark { | ||
|
|
||
| static final int VALUE_COUNT = 100_000; | ||
| private static final int INIT_SLAB = 64 * 1024; | ||
| private static final int PAGE = 4 * 1024 * 1024; | ||
|
|
||
| @Param({"3", "8", "16"}) | ||
| public int bitWidth; | ||
|
|
||
| @Param({"rle", "packed", "mixed"}) | ||
| public String pattern; | ||
|
|
||
| private byte[] encoded; | ||
|
|
||
| @Setup(Level.Trial) | ||
| public void setup() throws Exception { | ||
| int mask = bitWidth == 32 ? -1 : ((1 << bitWidth) - 1); | ||
| RunLengthBitPackingHybridEncoder enc = | ||
| new RunLengthBitPackingHybridEncoder(bitWidth, INIT_SLAB, PAGE, new DirectByteBufferAllocator()); | ||
| Random r = new Random(42); | ||
| switch (pattern) { | ||
| case "rle": | ||
| // Long stretches of the same value -> the encoder emits RLE runs. | ||
| for (int i = 0; i < VALUE_COUNT; i++) { | ||
| enc.writeInt(((i / 500) & 0x1F) & mask); | ||
| } | ||
| break; | ||
| case "packed": | ||
| // Random values -> the encoder emits bit-packed groups. | ||
| for (int i = 0; i < VALUE_COUNT; i++) { | ||
| enc.writeInt(r.nextInt() & mask); | ||
| } | ||
| break; | ||
| case "mixed": | ||
| // Alternating 250-value RLE blocks and 250-value random blocks. | ||
| for (int block = 0; block * 250 < VALUE_COUNT; block++) { | ||
| int val = r.nextInt() & mask; | ||
| boolean rle = (block & 1) == 0; | ||
| int limit = Math.min(250, VALUE_COUNT - block * 250); | ||
| for (int j = 0; j < limit; j++) { | ||
| enc.writeInt(rle ? val : (r.nextInt() & mask)); | ||
| } | ||
| } | ||
| break; | ||
| default: | ||
| throw new IllegalArgumentException("unknown pattern: " + pattern); | ||
| } | ||
| encoded = enc.toBytes().toByteArray(); | ||
| } | ||
|
|
||
| @Benchmark | ||
| @OperationsPerInvocation(VALUE_COUNT) | ||
| public void skip() throws Exception { | ||
| ByteBufferInputStream in = ByteBufferInputStream.wrap(ByteBuffer.wrap(encoded)); | ||
| RunLengthBitPackingHybridDecoder dec = new RunLengthBitPackingHybridDecoder(bitWidth, in); | ||
| dec.skipInts(VALUE_COUNT); | ||
| } | ||
|
|
||
| @Benchmark | ||
| @OperationsPerInvocation(VALUE_COUNT) | ||
| public int readSkip() throws Exception { | ||
| ByteBufferInputStream in = ByteBufferInputStream.wrap(ByteBuffer.wrap(encoded)); | ||
| RunLengthBitPackingHybridDecoder dec = new RunLengthBitPackingHybridDecoder(bitWidth, in); | ||
| int sink = 0; | ||
| for (int i = 0; i < VALUE_COUNT; i++) { | ||
| sink ^= dec.readInt(); | ||
| } | ||
| return sink; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DictionaryValuesReader#initFromPagehas this code:Specifically in the
else, we create a specialRunLengthBitPackingHybridDecoderfor empty dictionary pages. Should we override that decoder'sskipIntsto preserve the sameIOExceptionbehavior when skipping? Otherwise, we bypassreadIntand callreadNextin the skip path, which throwsIllegalArgumentException.