Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TsFile C++ Read Path Performance Optimization — Overview
Background
The current TsFile C++ read path uses row-by-row decoding with a row-oriented result set API. In full-scan and filtered query scenarios, throughput falls behind Parquet+Arrow. This optimization aims to make TsFile batch read throughput significantly exceed Parquet+Arrow while maintaining interface compatibility.
Summary of Optimizations
The optimizations span four layers:
1. Batch Decode Infrastructure
read_batch_int32/int64/float/doubleandskip_*batch interfaces to Decoder (PLAIN / TS2DIFF / Gorilla), processing 129 values per call instead of one virtual-dispatch per value.satisfy_batch_timebatch filter interface to Filter, evaluating an entire batch of timestamps at once.__builtin_bswap64/32(compiles to a single ARMREVinstruction) and skips theread_bufintermediate copy.2. Single-Column Batch Read Path
DECODE_TV_BATCHmethod in ChunkReader / AlignedChunkReader: decodes time + value in batches of 129 rows, applies batch filter, and writes results into TsBlock.get_next_tsblockto return TsBlock directly to the user.3. Multi-Value Column Merged Read
MultiAlignedTimeseriesIndexto allow a single AlignedChunkReader to hold 1 time column + N value columns simultaneously.VectorMeasurementColumnContextwraps a multi-value SSI; SingleDeviceTsBlockReader automatically detects and merges multiple measurements within the same device.SingleDeviceTsBlockReader::close()where multiple map entries pointed to the sameVectorMeasurementColumnContext.get_cur_page_header(previously sharedfile_data_value_buf_size_caused heap-buffer-overflow when columns had different page sizes).4. Parallel Decode + Batch Append Fast Path
DecodeThreadPoolfor page-level parallel decompression of N value columns (Snappy decompress in parallel).multi_DECODE_TV_BATCH, when all rows pass the filter and no column has nulls, the per-rowrow_appender.append()loop is bypassed — each column's decoded batch is written to the Vector buffer in a singlememcpy.Test Dataset
Benchmark Results
TAG_FILTER — filter by device id, read 100,000 rows × 4 value columns from a single device:
TIME_FILTER — filter by time range, read 333,333 rows × 4 value columns across all devices:
Phase Timing Breakdown (Post-Optimization)
Instrumented timing of each phase within
multi_DECODE_TV_BATCH:PR Plan
Split into 5 PRs, merged in dependency order:
PR 1 → 2 → 3 → 4 have sequential dependencies and must be merged in order. PR 5 has no dependencies and can be merged independently.
Correctness Verification