apache / apache/parquet-java

byte array has better performance than ByteBuffer

オープン
#2,713 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
Component: Parquet Priority: Major Type: enhancement
主要言語
Java
スター
3.1k
フォーク
1.6k
平均マージ
3日 12時間
マージ済み PR(30日)
33

説明

Currently the The abstract class BytePacker has the following method

@Deprecated
public void unpack8Values(final byte[] input, final int inPos, final int[] output, final int outPos) {
    unpack8Values(ByteBuffer.wrap(input), inPos, output, outPos);

}

I don’t know why to use ByteBuffer wrap byte[], ByteBuffer has poor performance.

 

I suggest using  

public abstract void unpack8Values(final byte[]input, final int inPos, final int[] output, final int outPos);

to replace

@Deprecated
public void unpack8Values(final byte[] input, final int inPos, final int[] output, final int outPos) {
    unpack8Values(ByteBuffer.wrap(input), inPos, output, outPos);

}

 

 

Tested by me the byte array api has better performance than ByteBuffer api, 

My test result is:

[Unpack8ValuesByteArray spent time] 80 ms
[Unpack8ValuesByteBuffer spent time] 133 ms

 

My test code is:

package org.apache.parquet.column.values.bitpacking;

import java.nio.ByteBuffer;

public class ByteBufferTest {
  private static final BytePacker bytePacker = Packer.LITTLE_ENDIAN.newBytePacker(7);

  private static final int COUNT = 100000;

  public static void main(String[] args) {
    byte  [] in  = new byte[1008];
    int [] out = new int[1152];
    int [] out1 = new int[1152];
    int [] out2 = new int[1152];

    int res = 0;

    for(int i = 0; i < in.length; i++) {
      in[i] = (byte) i;
    }

    for(int i = 0; i < COUNT; i++) {
      res += unpack8ValuesBytes(in, out, i % out.length);
    }

    res = 0;
    long t1 = System.currentTimeMillis();
    for(int i = 0; i < COUNT; i++) {
      res += unpack8ValuesBytes(in, out1, i % out.length);
    }
    long t2 = System.currentTimeMillis();
    System.out.println("[Unpack8ValuesByteArray spent time] " + (t2-t1) + " ms");

    ByteBuffer byteBuffer = ByteBuffer.wrap(in);

    for(int i = 0; i < COUNT; i++) {
      res += unpack8ValuesByteBuffer(byteBuffer, out, i % out.length);
    }

    res = 0;
    long t3 = System.currentTimeMillis();
    for(int i = 0; i < COUNT; i++) {
      res += unpack8ValuesByteBuffer(byteBuffer, out2, i % out.length);
    }
    long t4 = System.currentTimeMillis();
    System.out.println("[Unpack8ValuesByteBuffer spent time] " + (t4-t3) + " ms");

    for (int i=0; i**Note**: *This issue was originally created as [PARQUET-2189](https://issues.apache.org/jira/browse/PARQUET-2189). Please see the [migration documentation](https://issues.apache.org/jira/browse/PARQUET-2502) for further details.*

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

抽象的な BytePacker.unpack8Values オーバーロードから始め、提供された ByteBufferTest エントリーポイントを確認し、この API の変更によって影響を受ける実装を特定します。byte-array と ByteBuffer の動作およびベンチマーク結果を比較します。byte-array パスがアンパックされた値を保持し、そのパフォーマンス上の利点が検証されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java
領域
data, performance
issue の種類
リファクタリング
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。