Skip to content

Upgrade vendored HdrHistogram_c to 0.12.0 - #563

Merged
fcostaoliveira merged 2 commits into
masterfrom
upgrade/hdrhistogram-0.12.0
Oct 12, 2026
Merged

fcostaoliveira merged 2 commits into
masterfrom
upgrade/hdrhistogram-0.12.0

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Upgrade the vendored HdrHistogram_c to 0.12.0, using the unmodified upstream core-plus-log amalgamation from commit 8885476fc83fa362fec2fb2b5e9cd9544514976e. Include release provenance and SHA-256 checksums for all eight vendored source/header files, verified automatically by make check. Document the nullable JSON error result and update TSan suppression references.

Preserve memtier's existing lower and upper latency clamping through a shared application wrapper; upstream's capped helpers permit zero. Replace the local encoding entry point with hdr_log_encode, handle encoding errors in JSON output, and use the upstream percentile/count helpers. The Prometheus tests now exercise the production clamp wrapper instead of a duplicate implementation.

Add compatibility coverage for boundary values, atomic recording, a histogram encoded by the previously vendored library, V2 round trips, and JSON/HDR-log agreement. Update source-distribution lists, including previously omitted Memcached headers and bash completion discovered by building the release archive. Packed storage and rolling windows remain follow-up work.

Validation:

  • Latest-head GitHub CI: 119 passed, 6 intentionally skipped, including ASan, TSan, UBSan, coverage, distro and RPM checks.

  • Linux ARM64 GCC 13: TLS-enabled default build and all four make check programs pass.

  • Source archive: build with --disable-prometheus, all four unit programs, and vendored checksums pass.

  • HDR, realtime latency, Prometheus and StatsD integration suites: 32/33 pass. The IPv6 exporter test fails with “no IPv6 announce”; the same isolated test also fails on unmodified master 2ed605f54b09ad6d38ed416663ab2d086a02b24c in this container.

  • New JSON/HDR export integration test passes over both plaintext and TLS.

  • HDR compatibility tests pass under ASan+UBSan on Linux ARM64 and native macOS ARM64.

  • make format, make format-check, and the staged formatting hook pass. Vendored files retain upstream bytes, including upstream whitespace.

  • Fresh upstream release download: archive SHA-256 and all eight vendored files match the upstream asset and manifest.

  • Five paired local Linux ARM64 TLS/pipeline-16 runs: median throughput −0.074%, client CPU/op +0.188%, within observed spread. Raw results, provenance, script and limitations.

Closes #561.


Note

Medium Risk
Touches the core latency histogram path and changes JSON histogram encoding, but behavior is guarded by new unit/integration tests and vendor checksum gates; wire format remains V2-compatible with prior exports per tests.

Overview
Upgrades vendored HdrHistogram_c from 0.11.0 to the upstream 0.12.0 core-plus-log amalgamation, with SHA256SUMS and a make check / check-hdr-vendor step so CI verifies the eight vendored files match the release asset.

Latency recording and export move behind a new latency_histogram.h wrapper (memtier_record_latency / _atomic) that keeps memtier’s lower-bound clamp (values below lowest_discernible_value are raised) while using upstream capped helpers and the renamed HDR API. All stats paths that recorded latencies now call the wrapper instead of inline hdr_record_value_capped logic.

JSON percentile output now embeds histograms via standard hdr_log_encode (V2 compressed base64) instead of the removed local hdr_string_write; encode failures log to stderr and emit JSON null for Compressed Histogram. README documents that field for consumers.

Build and tests: adds hdr_histogram_test and integration coverage (test_hdr_histogram.py) for V2 round-trips, legacy wire compatibility, and JSON vs .hgrm agreement; Prometheus unit tests use the same wrapper as production. Minor release packaging fixes (dist_completions_DATA, extra headers in EXTRA_DIST / sources).

Reviewed by Cursor Bugbot for commit d5f1ba4. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

🤖 Automated first-pass review — a human maintainer's review is still required before merge.

Thanks for this. I went through the non-vendored parts in detail and skimmed the amalgamation. A few comments below.

On JSON compat, I checked the old local hdr_string_write against the old hdr_log_encode. Both do hdr_encode_compressed followed by base64, so as far as I can tell the Compressed Histogram wire format is unchanged. test_codec_and_percentiles decodes a blob produced by the previous library, and test_hdr_json_and_log_exports_agree checks that the JSON and .hgrm payloads match byte for byte. Together those cover the compat question well. The new null on the error path is technically a schema change, but the old code passed an uninitialized char * to write_obj whenever encoding failed, so I think null is the right choice and it's documented in the README.

A few questions:

  • Provenance: SHA256SUMS is added in this same PR, so check-hdr-vendor only proves the files still match what this PR recorded. It doesn't prove they match upstream. I can't check the release asset from here. Before merge, I think someone should download hdr_histogram-amalgamation-with-log-0.12.0.zip from the upstream release page once and confirm both the asset hash in deps/hdr_histogram/README.md and the per-file hashes. This is a ~1.5k-line dependency drop, and a human should look at it at least once rather than trusting the checksum file it ships with.

  • Hot path: update_*_op records into 3–4 histograms per request. With this change the atomic recorder becomes an out-of-line call instead of the old static inline in run_stats.cpp. Upstream also adds a prefetch and an extra branch in counts_inc_normalised, and our wrapper clamps before upstream clamps again. I'd expect the impact to be negligible, but did you happen to compare throughput before and after on a high-rate pipelined run? Since this is the measuring tool, a quick sanity number in the PR would be reassuring.

  • The new AVX2 path in get_value_from_idx_up_to_count calls __builtin_cpu_supports("avx2") on every percentile lookup. That's not hot, so it's fine. I'm only mentioning it because whoever owns the legacy/old-toolchain CI jobs may want to confirm that __attribute__((target("avx2"))) and <immintrin.h> are happy everywhere we build, not just on the default runners. HDR_DISABLE_AVX2 exists as an escape hatch if not.

Nitpicking: the Makefile.am fixes for the Memcached headers and dist_completions_DATA are unrelated to the HDR upgrade. You already called them out in the description, so they're fine here. I'd just mention them in the commit message so they're easy to find later.

The integration itself looks solid to me. Keeping the clamp policy in latency_histogram.h instead of patching vendored code is the right call, and replacing the source-pinned grep with tests that exercise the real wrapper is a nice cleanup. I'd mainly want the upstream hash confirmed by a human before this goes in.

(would file this as a comment, not a formal block)

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Addressed the first-pass review in d5f1ba4:

  • make check now verifies all eight vendored files against SHA256SUMS, so the local gate and the existing Linux/macOS unit-test CI jobs enforce this automatically. make check-hdr-vendor also runs it independently. The target supports both sha256sum and macOS shasum. Verified it accepts the release bytes and rejects a modified copy; Linux make check passes all four test programs plus the checksum check.
  • Updated the TSan suppression comment to name memtier_record_latency_atomic in latency_histogram.h, removed stale line numbers, and distinguished the now-atomic hdr_total_count load from hdr_add's plain count reads.
  • The encoding-error null is intentional: there is no valid encoded histogram to return on that path, and the previous unchecked path did not provide a reliable string on failure. Successful output retains the same string and V2 format. README now documents the nullable error case, stderr diagnostic, and required consumer check.
  • Checked the configured smoke matrix: Ubuntu noble/jammy/focal/resolute and Debian bookworm/bullseye/trixie; bionic is not currently selected. The initial revision also passed the EL8 x86_64 and aarch64 RPM builds, covering the oldest RPM toolchain in this matrix. New-head CI is running after the follow-up.

@fcostaoliveira

fcostaoliveira commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator Author

Follow-up on the provenance and hot-path questions for d5f1ba4:

  • Downloaded a fresh copy of hdr_histogram-amalgamation-with-log-0.12.0.zip and the upstream release checksum manifest. The archive SHA256 is 5fae248faedfcae85731530ecabe2cd485810b7b33055b30fce97ad7638e3527, matching the documented value and upstream manifest. All eight vendored C/header files are byte-for-byte identical to the archive and match upstream per-file hashes. This is automated verification; the draft still awaits maintainer review.
  • Ran five paired, alternating-order baseline/upgrade measurements against one fixed Redis process, with TLS, pipeline 16, 3 threads × 10 clients, ratio 1:10, 32-byte values, and 10-second measurement windows. Client and server CPU affinity were separate. Baseline is PR base 2ed605f; upgrade code matches this head.
Metric Baseline median (min–max) Upgrade median (min–max) Median change
Operations/sec 2,765,458 (2,750,307–2,791,935) 2,763,405 (2,745,285–2,778,841) −0.074%
Client CPU ns/op 489.84 (485.46–498.46) 490.76 (489.86–496.68) +0.188%

No material regression is visible within this run's spread. This is a local Linux ARM64 sanity check in a shared four-vCPU Colima VM on an Apple M6; a fixed single-CPU Redis can limit throughput. It is not a cross-platform performance result or proof of equivalence. The upgrade binary's version stamp is b670072 because it was compiled before the subsequent documentation/Makefile-only commit.

Reproduction script, provenance, all ten raw JSON results, CPU samples, and summary are committed in workspace commit 3648647. Summary · Provenance · Script.

The old-toolchain question is covered by the configured distro smoke matrix and successful EL8 x86_64/aarch64 RPM builds noted above. Final latest-head CI result: 119 passed, 6 intentionally skipped, no failures or pending jobs at d5f1ba48131a982be5a25001c04e369ec719df3e. There are no unresolved inline review threads. The PR remains draft for maintainer review.

@fcostaoliveira
fcostaoliveira marked this pull request as ready for review October 12, 2026 21:12
@fcostaoliveira
fcostaoliveira merged commit f907a60 into master Oct 12, 2026
126 checks passed
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.

Upgrade the vendored HdrHistogram_c to 0.12.0 (packed histograms, faster percentile queries)

1 participant