-
Notifications
You must be signed in to change notification settings - Fork 711
perf: improve metrics signature #8879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
This PR optimizes the performance-critical signature_without_labels function by replacing std::hash::DefaultHasher with ahash::AHasher, addressing a 14% performance bottleneck in histogram queries processing 450,000 series.
Key Changes
- Performance Optimization: Switched from
DefaultHashertoAHasherinsignature_without_labels()function (src/service/promql/value.rs:793) - Test Improvements: Updated tests to verify deterministic behavior instead of relying on hardcoded hash values, making tests more robust across hash algorithm changes
- Profiling Support: Added
split-debuginfo = "packed"to profliing profile for better debugging capabilities - Code Formatting: Minor formatting improvements to dependency lists in Cargo.toml
Performance Impact
The signature function is heavily used throughout the PromQL engine:
- Called in aggregation operations (sum, avg, count, etc.) to group metrics by label sets
- Used in binary vector operations for matching time series
- Critical for duplicate label set detection
AHasher from the ahash crate provides significantly faster hashing than DefaultHasher, especially for small keys like metric labels, while maintaining good hash distribution.
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- This is a well-isolated performance optimization with proper test coverage. The change from DefaultHasher to AHasher is a straightforward swap that maintains the same interface. The ahash dependency was already in use in the codebase, and tests were updated to verify deterministic behavior rather than specific hash values, making them more resilient to future changes.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| src/service/promql/value.rs | 5/5 | Replaced std::hash::DefaultHasher with ahash::AHasher in signature_without_labels function for better performance and updated tests to verify deterministic behavior instead of hardcoded hash values |
| Cargo.toml | 5/5 | Added profiling configuration (split-debuginfo = "packed") and reformatted dependencies for consistency |
Sequence Diagram
sequenceDiagram
participant Query as PromQL Query
participant Agg as Aggregation Module
participant Sig as signature_without_labels()
participant Hash as AHasher
participant Map as HashMap<u64, T>
Query->>Agg: Execute aggregation (e.g., sum, avg)
loop For each metric series
Agg->>Sig: Calculate signature(labels)
Sig->>Hash: Create AHasher::default()
Note over Hash: Previously: DefaultHasher::new()
loop For each label
Sig->>Hash: write(name.as_bytes())
Sig->>Hash: write(value.as_bytes())
end
Sig->>Hash: finish()
Hash-->>Sig: Return u64 hash
Sig-->>Agg: Return signature
Agg->>Map: Group by signature
end
Map-->>Query: Aggregated results
2 files reviewed, no comments
|
This is my benchmark result: https://github.com/hengfeiyang/hello_world_rust/tree/main/hash |
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 365 | 343 | 0 | 19 | 3 | 94% | 4m 39s |
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 365 | 343 | 0 | 19 | 3 | 94% | 4m 39s |
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 365 | 341 | 0 | 19 | 5 | 93% | 5m 1s |
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 365 | 345 | 0 | 19 | 1 | 95% | 4m 40s |
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 365 | 342 | 0 | 19 | 4 | 94% | 4m 38s |
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 365 | 342 | 0 | 19 | 4 | 94% | 4m 42s |
the signature is take 14% percent of time for calculate 45w series histogram query.
split-debuginfo = "packed"to generate symbol table for profiling in macos