Hi all,

I have opened a PR to optimize several frequently executed batch decoding and 
result-writing paths in the TsFile C++ Reader:

https://github.com/apache/tsfile/pull/898

This PR contains four optimizations:

1. Fixed-width batch append

Adds a contiguous batch append path for fixed-width data types, reducing 
per-value function calls, capacity checks, and state updates.

2. TS2DIFF zero-bit-width fast path

When timestamp deltas remain unchanged and the encoded bit width is zero, 
timestamps are generated directly as an arithmetic progression, avoiding 
per-value bitstream reads.

3. Gorilla consecutive zero-control-bit processing

Consumes consecutive zero control bits in batches, reducing repeated bitstream 
operations and conditional branches.

4. Gorilla whole-run repeated-value output

When a run of floating-point values reuses the previous value, the entire run 
is written using a batch fill operation instead of appending values 
individually.

Individual A/B measurements were performed for these hot paths:

- Fixed-width batch append achieved approximately 1.89x the original throughput.
- The TS2DIFF zero-bit-width path achieved approximately 1.30x the original 
throughput.
- Gorilla consecutive zero-control-bit processing achieved approximately 1.11x 
the original throughput.
- Gorilla whole-run output reduced median latency by approximately 1.72%.

These results are intended to verify the effect of each local fast path. They 
should not be multiplied together and do not represent an overall performance 
improvement across all data types and query workloads.

The changes do not modify the TsFile file format or public APIs, and they 
preserve the existing decoding results. The relevant C++ tests and code 
formatting checks have passed.

Reviews and suggestions regarding the implementation, applicable workloads, and 
possible follow-up optimizations are welcome.

Best regards,
Colin

Reply via email to