Skip to content

PivCoHuffman implementation - #61

Draft
Sanya239 wants to merge 14 commits into
mainfrom
PivCo-Huffman
Draft

PivCoHuffman implementation#61
Sanya239 wants to merge 14 commits into
mainfrom
PivCo-Huffman

Conversation

@Sanya239

Copy link
Copy Markdown
Collaborator

No description provided.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9f80561440

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +387 to +390
static T read(std::span<const std::byte> data, std::size_t& pos) {
T value;
std::memcpy(&value, data.data() + pos, sizeof(T));
pos += sizeof(T);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate compressed input before reading

When callers load a truncated or corrupt persisted stream through the public std::span<const std::byte> constructor, this helper unconditionally copies sizeof(T) bytes from data.data() + pos without checking that the bytes exist; a 1-byte span already reads past the buffer in the first header read, and later node/bitmap reads have the same issue. The deserializer should reject malformed streams before copying or indexing into decoded nodes rather than relying on the input being perfectly formed.

Useful? React with 👍 / 👎.

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.04309% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.35%. Comparing base (bf01091) to head (58937fe).

Files with missing lines Patch % Lines
include/pixie/huffman/pivco_huffman.h 91.74% 21 Missing and 25 partials ⚠️
src/tests/pivco_huffman_tests.cpp 99.55% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #61      +/-   ##
==========================================
+ Coverage   90.10%   90.35%   +0.25%     
==========================================
  Files          39       43       +4     
  Lines        8735    10010    +1275     
  Branches     1418     1612     +194     
==========================================
+ Hits         7871     9045    +1174     
- Misses        447      511      +64     
- Partials      417      454      +37     
Flag Coverage Δ
gcov 90.35% <94.04%> (+0.25%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Sanya239
Sanya239 marked this pull request as draft July 21, 2026 16:35
@Malkovsky

Copy link
Copy Markdown
Owner

@codex please run Huffman benchmarks and summarize throughput

@@ -0,0 +1,222 @@
#include <benchmark/benchmark.h>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make it a general Huffman benchmark

/// serialize the compressed stream. The compressed size is read from
/// the first timed iteration (no separate probe build), which keeps
/// gigabyte-scale setup cost to a single encode.
void BM_Encode(benchmark::State& state, DatasetMaker make) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make it a general benchmark templated by the implementation

@chatgpt-codex-connector

Copy link
Copy Markdown

Huffman Benchmark Summary

I built the native benchmark targets and ran the complete set of 22 PivCo-Huffman encode/decode dataset variants at the 1 MiB input tier. This tier was selected to provide stable throughput measurements without conflating the results with the cache-resident 1 KiB cases or the substantial memory pressure of the 1 GiB cases. The benchmark’s supported sweep is 1 KiB, 1 MiB, and 1 GiB. src/benchmarks/pivco_huffman_benchmarks.cppL136-L142

The figures below are the median real-time throughput across five repetitions, using the benchmark’s default deterministic seed of 42. The harness explicitly uses real time, five repetitions, and aggregate-only reporting. src/benchmarks/pivco_huffman_benchmarks.cppL25-L34 src/benchmarks/pivco_huffman_benchmarks.cppL191-L198

Results

Dataset Encode Decode Compressed size
Uniform256 107.0 MiB/s 5,860.1 MiB/s 8.003 bpb
Binary 1,161.0 MiB/s 12,247.6 MiB/s 1.003 bpb
LowEntropy4 982.8 MiB/s 9,210.6 MiB/s 2.003 bpb
Uniform8 971.5 MiB/s 684.0 MiB/s 3.003 bpb
Uniform16 1,050.0 MiB/s 8,083.2 MiB/s 4.003 bpb
Uniform32 920.4 MiB/s 544.3 MiB/s 5.003 bpb
Uniform64 941.8 MiB/s 569.4 MiB/s 6.003 bpb
Uniform128 119.6 MiB/s 576.1 MiB/s 7.003 bpb
TextLike 240.8 MiB/s 589.4 MiB/s 4.801 bpb
Skewed99 754.4 MiB/s 3,599.9 MiB/s 1.122 bpb
SingleSymbol 1,087.8 MiB/s 18,995.5 MiB/s 0.002 bpb

The bpb column is serialized compressed bits per input byte, including format overhead. src/benchmarks/pivco_huffman_benchmarks.cppL128-L134

Interpretation

  • Encode throughput ranges from 107 MiB/s to 1.13 GiB/s.

    • The fastest non-degenerate case is Binary at approximately 1.13 GiB/s.
    • Uniform16, LowEntropy4, and Uniform8 also encode at roughly 0.95–1.03 GiB/s.
    • Uniform256 and Uniform128 are the slowest encode cases, at 107 MiB/s and 120 MiB/s.
    • Text-like input reaches 241 MiB/s while compressing to 4.80 bits per byte.
  • Decode throughput is highly dependent on alphabet shape.

    • Binary reaches approximately 12.0 GiB/s.
    • LowEntropy4 reaches 9.0 GiB/s, while Uniform16 reaches 7.9 GiB/s.
    • Uniform256 reaches 5.72 GiB/s, despite its poor compression ratio.
    • Uniform8 and the 32–128-symbol cases form a much slower group at approximately 544–684 MiB/s.
    • This sharp non-monotonic behavior suggests that different tree shapes or SIMD decode paths dominate performance rather than code depth alone.
  • Skewed data performs well in both directions.

    • Skewed99 encodes at 754 MiB/s, decodes at 3.52 GiB/s, and occupies 1.122 bpb.
  • SingleSymbol is a degenerate fast path.

    • Its 18.6 GiB/s decode result should not be treated as representative general-purpose Huffman throughput.
    • Its reported 0.002 bpb consists almost entirely of fixed serialization overhead because no routing bitmap is required.

The encode measurement includes Huffman-tree construction, bitmap population, and serialization. src/benchmarks/pivco_huffman_benchmarks.cppL146-L165 Decode measures reconstruction from an already-built in-memory codec; construction is outside the timed loop. src/benchmarks/pivco_huffman_benchmarks.cppL168-L183

Environment

  • Intel Xeon Platinum 8370C virtualized host
  • 3 exposed logical CPUs
  • GCC 13.3
  • Release build with -march=native
  • AVX-512 enabled
  • Results are single-host snapshots and should not be interpreted as cross-machine performance guarantees.

Checks Performed

  • cmake --preset benchmarks
  • cmake --build --preset benchmarks --target pivco_huffman_benchmarks pivco_huffman_file_benchmarks -j2
  • ./build/benchmarks/pivco_huffman_benchmarks --benchmark_filter='/1048576/' --benchmark_out=/tmp/pivco-huffman-1mib.json --benchmark_out_format=json
  • python3 - <<'PY' ... PY — extracted median throughput and compression ratios from the Google Benchmark JSON output.
  • git status --short --branch — working tree remained clean.

No repository files were changed, so no commit or follow-up pull request was created.

View task →

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants