Skip to content

perf: optimize extrapolated rate op family#7880

Open
waynexia wants to merge 4 commits intomainfrom
rate-op
Open

perf: optimize extrapolated rate op family#7880
waynexia wants to merge 4 commits intomainfrom
rate-op

Conversation

@waynexia
Copy link
Copy Markdown
Member

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

What's changed and what's your intention?

improve the performance by accessing the range array directly, removing unnecessary float op, and memoizing counter reset result etc.

benchmark result:

Details
range_fn/rate_counter/n1000_w10
                        time:   [9.1651 µs 9.1732 µs 9.1829 µs]
                        change: [−45.095% −44.954% −44.856%] (p = 0.00 < 0.05)
                        Performance has improved.
range_fn/rate_counter/n10000_w10
                        time:   [86.475 µs 86.546 µs 86.626 µs]
                        change: [−45.009% −44.922% −44.847%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe
range_fn/rate_counter/n10000_w60
                        time:   [85.712 µs 85.741 µs 85.780 µs]
                        change: [−83.935% −83.910% −83.888%] (p = 0.00 < 0.05)
                        Performance has improved.
range_fn/rate_counter/n10000_w360
                        time:   [83.565 µs 83.609 µs 83.649 µs]
                        change: [−97.308% −97.304% −97.301%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) low mild
range_fn/rate_counter_reset/n1000_w10
                        time:   [9.3010 µs 9.3087 µs 9.3164 µs]
                        change: [−45.265% −45.219% −45.172%] (p = 0.00 < 0.05)
                        Performance has improved.
range_fn/rate_counter_reset/n10000_w10
                        time:   [87.591 µs 87.666 µs 87.736 µs]
                        change: [−45.067% −45.001% −44.933%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 2 outliers among 100 measurements (2.00%)
  1 (1.00%) high mild
  1 (1.00%) high severe
range_fn/rate_counter_reset/n10000_w60
                        time:   [85.986 µs 86.033 µs 86.087 µs]
                        change: [−83.899% −83.882% −83.866%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
range_fn/rate_counter_reset/n10000_w360
                        time:   [83.709 µs 83.758 µs 83.821 µs]
                        change: [−97.302% −97.298% −97.295%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 7 outliers among 100 measurements (7.00%)
  6 (6.00%) high mild
  1 (1.00%) high severe
range_fn/increase_counter/n1000_w10
                        time:   [8.4861 µs 8.4934 µs 8.5036 µs]
                        change: [−45.531% −45.486% −45.440%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) high mild
  1 (1.00%) high severe
range_fn/increase_counter/n10000_w10
                        time:   [80.202 µs 80.254 µs 80.308 µs]
                        change: [−44.946% −44.900% −44.854%] (p = 0.00 < 0.05)
                        Performance has improved.
range_fn/increase_counter/n10000_w60
                        time:   [79.687 µs 79.732 µs 79.777 µs]
                        change: [−85.022% −85.002% −84.984%] (p = 0.00 < 0.05)
                        Performance has improved.
range_fn/increase_counter/n10000_w360
                        time:   [77.011 µs 77.063 µs 77.110 µs]
                        change: [−97.507% −97.504% −97.500%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high mild
range_fn/increase_counter_reset/n1000_w10
                        time:   [8.7879 µs 8.7941 µs 8.8003 µs]
                        change: [−44.081% −43.999% −43.914%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 10 outliers among 100 measurements (10.00%)
  6 (6.00%) high mild
  4 (4.00%) high severe
range_fn/increase_counter_reset/n10000_w10
                        time:   [80.809 µs 80.897 µs 80.976 µs]
                        change: [−45.495% −45.380% −45.287%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
range_fn/increase_counter_reset/n10000_w60
                        time:   [79.217 µs 79.263 µs 79.307 µs]
                        change: [−85.150% −85.134% −85.120%] (p = 0.00 < 0.05)
                        Performance has improved.
range_fn/increase_counter_reset/n10000_w360
                        time:   [76.832 µs 76.867 µs 76.910 µs]
                        change: [−97.520% −97.516% −97.513%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) high mild
  1 (1.00%) high severe
range_fn/delta_gauge/n1000_w10
                        time:   [7.1103 µs 7.1140 µs 7.1172 µs]
                        change: [−28.739% −28.697% −28.653%] (p = 0.00 < 0.05)
                        Performance has improved.
range_fn/delta_gauge/n10000_w10
                        time:   [65.541 µs 65.583 µs 65.619 µs]
                        change: [−26.503% −26.388% −26.291%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe
range_fn/delta_gauge/n10000_w60
                        time:   [65.110 µs 65.166 µs 65.217 µs]
                        change: [−26.631% −26.579% −26.528%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 21 outliers among 100 measurements (21.00%)
  21 (21.00%) high severe
range_fn/delta_gauge/n10000_w360
                        time:   [63.091 µs 63.126 µs 63.160 µs]
                        change: [−26.737% −26.694% −26.652%] (p = 0.00 < 0.05)
                        Performance has improved.

PR Checklist

Please convert it to a draft if some of the following conditions are not met.

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.
  • API changes are backward compatible.
  • Schema or data changes are backward compatible.

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
@github-actions github-actions bot added size/M docs-not-required This change does not impact docs. labels Mar 28, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the ExtrapolatedRate calculation logic, introducing more robust error handling for input types and window layouts. It optimizes counter correction by incrementally updating values for contiguous windows and transitions to using Float64Builder for result construction. Additionally, the PR includes comprehensive unit tests covering various error scenarios and counter reset behaviors. Review feedback suggests marking the (false, true) match arm in func_name as unreachable to clarify that gauge rates are not supported by this specific function.

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-not-required This change does not impact docs. size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant