Skip to content

refactor: C++ implementation of ROOT file hasher#5614

Open
paulgessinger wants to merge 7 commits into
acts-project:mainfrom
paulgessinger:refactor/cpp-root-hash
Open

refactor: C++ implementation of ROOT file hasher#5614
paulgessinger wants to merge 7 commits into
acts-project:mainfrom
paulgessinger:refactor/cpp-root-hash

Conversation

@paulgessinger

Copy link
Copy Markdown
Member

This is an implementation of the ROOT file hashing in C++. The hashes are not identical, but the guarantees should be the same. It should be strictly faster than the Ptyhon implementation.

--- END COMMIT MESSAGE ---

Any further description goes here, @-mentions are ok here!

  • Use a conventional commits prefix: quick summary
    • We mostly use feat, fix, refactor, docs, chore and build types.
  • A milestone will be assigned by one of the maintainers

@github-actions github-actions Bot added this to the next milestone Jun 24, 2026
@github-actions github-actions Bot added the Component - Examples Affects the Examples module label Jun 24, 2026
@paulgessinger paulgessinger force-pushed the refactor/cpp-root-hash branch 2 times, most recently from 3d31bbc to 9ef3bf9 Compare June 24, 2026 14:49
@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

📊: Physics performance monitoring for 88718a5

Full contents

physmon summary

❗️: Downstream build failure

  • eic-shell EICrecon (cc @acts-project/epic-contacts)

@benjaminhuth benjaminhuth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, a few comments. Do we know how much faster it is?

Comment thread Examples/Io/Root/src/RootFileHasher.cpp
Comment thread Examples/Io/Root/src/RootFileHasher.cpp Outdated
Comment thread Examples/Io/Root/src/RootFileHasher.cpp Outdated
Comment thread Examples/Io/Root/src/RootFileHasher.cpp Outdated
Comment thread Examples/Io/Root/src/RootFileHasher.cpp
@paulgessinger

Copy link
Copy Markdown
Member Author

@benjaminhuth i've found the C++ version runs in "constant" time (clearly it doesn't, but the file size in my benchmarks it didn't move). On the smallest files the perf is the same, for larger files I get speedups of 2x+

@paulgessinger

Copy link
Copy Markdown
Member Author

@benjaminhuth here are the benchmarks:

===================================================================
### tracksummary_ckf.root  (372K)
===================================================================
Benchmark 1: python-uproot
  Time (mean ± σ):     354.8 ms ±   8.0 ms    [User: 299.6 ms, System: 51.0 ms]
  Range (min … max):   343.1 ms … 368.1 ms    10 runs

Benchmark 2: cpp-sha256
  Time (mean ± σ):     343.0 ms ±   7.6 ms    [User: 277.8 ms, System: 58.7 ms]
  Range (min … max):   332.1 ms … 356.4 ms    10 runs

Summary
  cpp-sha256 ran
    1.03 ± 0.03 times faster than python-uproot

===================================================================
### hits.root  (504K)
===================================================================
Benchmark 1: python-uproot
  Time (mean ± σ):     849.9 ms ±  15.2 ms    [User: 789.3 ms, System: 55.1 ms]
  Range (min … max):   811.7 ms … 867.7 ms    10 runs

Benchmark 2: cpp-sha256
  Time (mean ± σ):     336.7 ms ±   8.5 ms    [User: 275.1 ms, System: 55.8 ms]
  Range (min … max):   324.3 ms … 351.9 ms    10 runs

Summary
  cpp-sha256 ran
    2.52 ± 0.08 times faster than python-uproot

===================================================================
### measurements.root  (1.1M)
===================================================================
Benchmark 1: python-uproot
  Time (mean ± σ):      2.169 s ±  0.051 s    [User: 2.089 s, System: 0.072 s]
  Range (min … max):    2.066 s …  2.247 s    10 runs

Benchmark 2: cpp-sha256
  Time (mean ± σ):     348.9 ms ±  11.1 ms    [User: 284.9 ms, System: 57.9 ms]
  Range (min … max):   336.2 ms … 365.3 ms    10 runs

Summary
  cpp-sha256 ran
    6.22 ± 0.25 times faster than python-uproot

@benjaminhuth

Copy link
Copy Markdown
Member

nice. 2s to 300ms is some good speedup.

@paulgessinger paulgessinger force-pushed the refactor/cpp-root-hash branch from db0d750 to 1f196f9 Compare July 3, 2026 11:24
paulgessinger and others added 7 commits July 6, 2026 09:54
Collapse the two duplicated Hasher class definitions into one, guarding
only the backend member and the two method bodies, and hoist the shared
"using Digest" out of the backend #if/#else so only kDigestSize stays
guarded there.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Use std::vector<std::byte> instead of std::string for the raw-byte
buffer fed to the hasher, matching the std::span<const std::byte>
consumer and expressing the intent (raw bytes, not text). A small
appendBytes helper replaces the repeated reinterpret_cast/append and
drops the std::as_bytes laundering at the call sites. Byte content is
unchanged, so hashes are identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replace the hand-rolled trim helper with boost::algorithm::trim_copy at
the two firstTemplateArg call sites. Behaviourally equivalent for the
type-name inputs parsed here.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Move the firstTemplateArg helper into a detail header
(RootFileHasherHelpers.hpp) so it can be exercised directly, and add a
Boost unit test covering simple, nested, top-level-comma, whitespace and
no-template cases.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@paulgessinger paulgessinger force-pushed the refactor/cpp-root-hash branch from 1f196f9 to 88718a5 Compare July 6, 2026 07:54
@sonarqubecloud

sonarqubecloud Bot commented Jul 6, 2026

Copy link
Copy Markdown

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants