facebookincubator / velox

A C++ vectorized database acceleration library aimed to optimizing query engines and data processing systems.
https://velox-lib.io/
Apache License 2.0
3.27k stars 1.08k forks source link

Optimize VectorHasher for large batchSize low cardinality input #6331

Open shiyu-bytedance opened 10 months ago

shiyu-bytedance commented 10 months ago

Description

Currently, for computeValueIds, VectorHasher consumes the entire input, either successfully hashing all values, or if an unhashable value is encountered, VectorHasher will still consume the entirety of the rest of the input in "AnalyzeValue" mode. So that subsequently, a "workable" new hashmode can be picked and rehash.

In the "fail to hash, analyze the remaining values" code path, current implementation is not optimal. Because current implementation calls "AnalyzeValue" on all values of the input vector. The optimal algorithm would only analyze the remaining values of input until "all unique values" of the "inner-most"/"decoded.base()" have been visited.

In low cardinality large batchsize workloads, this results in Nx improvement where if cardinality = C, batchSize = B, N = B / C.

In all other cases, this optimization is no worse than current implementation.

Real life workload example:

Age (say 0 y/o to 80 y/o)column of some large population (say 20mil). Even using batchSize of 1024, this optimization would result in 12.8x (1024/80)speed-up of computeValueIds.

@mbasmanova @oerling

shiyu-bytedance commented 10 months ago

cc @mbasmanova @oerling