Skip to content

test(bench): add encode_loop_z000033 example for clean encoder profiles#297

Open
polaz wants to merge 4 commits into
mainfrom
perf/#111-encode-profiling-bin
Open

test(bench): add encode_loop_z000033 example for clean encoder profiles#297
polaz wants to merge 4 commits into
mainfrom
perf/#111-encode-profiling-bin

Conversation

@polaz
Copy link
Copy Markdown
Member

@polaz polaz commented May 29, 2026

Summary

Adds encode_loop_z000033 example — the encode-side analog of decode_loop_z000033. Reads a raw corpus, loops compress_to_vec at a given level N times, no criterion and no FFI.

Why

The compare_ffi compress benchmark runs the donor (ZSTD_compress) in the same process, so cargo flamegraph on it mixes donor ZSTD_DUBT_findBestMatch / ZSTD_recordFingerprint symbols with ours — unusable for isolating the pure-Rust encoder hot path. This binary produces clean encoder perf-record samples.

black_box + len-sum sink defeats dead-code elimination of the compress call.

Usage

cargo flamegraph --example encode_loop_z000033 --features dict_builder \
  --profile flamegraph -- <level> <iters> zstd/decodecorpus_files/z000033

Used to map the Fast L-1 encode hot path (start_matching 25%, sequence-emit 30%, HUF encode4x 8%) for #111 Phase 7 work.

Related to #111.

Mirrors decode_loop_z000033 for the encode side: reads a raw corpus,
loops `compress_to_vec` at a given level N times, no criterion and no
FFI. The `compare_ffi` compress benchmark runs the donor in the same
process, so its flamegraph mixes `ZSTD_*` donor symbols with ours;
this binary isolates the pure-Rust encoder hot path for perf-record.

black_box + len-sum sink defeats dead-code elimination of the
compress call.
Copilot AI review requested due to automatic review settings May 29, 2026 03:36
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Warning

Review limit reached

@polaz, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 5 minutes and 36 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2ffb233c-c278-4278-bd7e-2df1cb0e1160

📥 Commits

Reviewing files that changed from the base of the PR and between 1efbb1d and 3d53902.

📒 Files selected for processing (1)
  • zstd/examples/encode_loop_z000033.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/#111-encode-profiling-bin

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new encode_loop_z000033 example binary intended for collecting clean perf/cargo flamegraph profiles of the pure-Rust encoder hot path without Criterion overhead or in-process C donor symbols.

Changes:

  • Add zstd/examples/encode_loop_z000033.rs example that reads a corpus (or generates a deterministic synthetic fallback) and repeatedly compresses it at a chosen level/iteration count.
  • Add a black_box/length-sum sink to prevent dead-code elimination of the compress work.

Comment thread zstd/examples/encode_loop_z000033.rs Outdated
Comment thread zstd/examples/encode_loop_z000033.rs Outdated
Comment thread zstd/examples/encode_loop_z000033.rs Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…er copy

The input is a contiguous `&[u8]`; `compress_to_vec` takes `impl Read`
and re-buffers it via `read_to_end` into a fresh `Vec` every
iteration, adding per-iter input allocation + memmove that pollutes
the encoder flamegraph. `compress_slice_to_vec` consumes the slice
directly, keeping the profile focused on the encode hot path.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread zstd/examples/encode_loop_z000033.rs
Comment thread zstd/examples/encode_loop_z000033.rs Outdated
polaz added 2 commits May 29, 2026 11:09
Allocate the output Vec once and clear()-reuse it every iteration so
steady-state iters do zero output-buffer allocation — keeps the
flamegraph on the encoder hot path instead of per-iter Vec growth +
first-touch page faults. Drive FrameCompressor directly over the
contiguous slice. Sync the module doc to the actual API used.
Copilot AI review requested due to automatic review settings May 29, 2026 08:22
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment on lines +17 to +20
//! Build: cargo build --profile flamegraph -p structured-zstd \
//! --example encode_loop_z000033 --features dict_builder
//! Run: cargo flamegraph --example encode_loop_z000033 --features dict_builder \
//! --profile flamegraph -- <level> <iters> <corpus_path>
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