Skip to content

Replace remaining regexps #21

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Replace remaining regexps #21

wants to merge 2 commits into from

Conversation

ArthurSens
Copy link
Member

@ArthurSens ArthurSens commented Mar 27, 2025

Building on top of #20, I've tried to replace the remaining regexps with rune comparisons + strings.Builder

Benchmark results for BuildCompliantMetricName (only function affected by the changes here):

arthursens$ benchstat main.txt no-regexp.txt 
goos: darwin
goarch: arm64
pkg: github.com/prometheus/otlptranslator
cpu: Apple M2 Pro
                                                                                      │   main.txt   │           no-regexp.txt            │
                                                                                      │    sec/op    │   sec/op     vs base               │
BuildCompliantMetricName/withSuffixes=true/Basic_metric_with_no_special_characters-2     188.7n ± 2%   146.1n ± 2%  -22.55% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Counter_metric-2                              246.2n ± 3%   203.2n ± 1%  -17.48% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Gauge_ratio_metric-2                          228.6n ± 0%   182.5n ± 1%  -20.13% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Metric_with_per-unit_suffix_notation-2        336.8n ± 2%   270.2n ± 3%  -19.77% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Metric_with_special_characters-2              247.7n ± 8%   208.7n ± 1%  -15.74% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Metric_starting_with_digit-2                  159.8n ± 1%   122.9n ± 6%  -23.07% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Metric_with_multiple_underscores-2            269.8n ± 0%   237.5n ± 2%  -11.97% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Metric_with_complex_unit-2                    474.2n ± 1%   384.8n ± 1%  -18.85% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Basic_metric_with_no_special_characters-2    760.1n ± 1%   107.2n ± 5%  -85.90% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Counter_metric-2                             812.5n ± 3%   111.7n ± 3%  -86.26% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Gauge_ratio_metric-2                         702.3n ± 4%   103.3n ± 1%  -85.29% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Metric_with_per-unit_suffix_notation-2      480.95n ± 1%   85.78n ± 1%  -82.17% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Metric_with_special_characters-2            1460.5n ± 2%   206.3n ± 3%  -85.87% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Metric_starting_with_digit-2                554.45n ± 3%   89.48n ± 3%  -83.86% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Metric_with_multiple_underscores-2          2003.5n ± 1%   215.3n ± 1%  -89.25% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Metric_with_complex_unit-2                   705.6n ± 1%   104.0n ± 1%  -85.26% (p=0.002 n=6)
geomean                                                                                  462.1n        158.0n       -65.81%

                                                                                      │  main.txt   │           no-regexp.txt           │
                                                                                      │    B/op     │    B/op     vs base               │
BuildCompliantMetricName/withSuffixes=true/Basic_metric_with_no_special_characters-2     160.0 ± 0%   128.0 ± 0%  -20.00% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Counter_metric-2                              288.0 ± 0%   256.0 ± 0%  -11.11% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Gauge_ratio_metric-2                          208.0 ± 0%   176.0 ± 0%  -15.38% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Metric_with_per-unit_suffix_notation-2        256.0 ± 0%   208.0 ± 0%  -18.75% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Metric_with_special_characters-2              240.0 ± 0%   208.0 ± 0%  -13.33% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Metric_starting_with_digit-2                 120.00 ± 0%   88.00 ± 0%  -26.67% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Metric_with_multiple_underscores-2            240.0 ± 0%   208.0 ± 0%  -13.33% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Metric_with_complex_unit-2                    368.0 ± 0%   304.0 ± 0%  -17.39% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Basic_metric_with_no_special_characters-2   100.00 ± 0%   48.00 ± 0%  -52.00% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Counter_metric-2                            104.00 ± 0%   48.00 ± 0%  -53.85% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Gauge_ratio_metric-2                         96.00 ± 0%   48.00 ± 0%  -50.00% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Metric_with_per-unit_suffix_notation-2       72.00 ± 0%   32.00 ± 0%  -55.56% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Metric_with_special_characters-2             245.0 ± 0%   112.0 ± 0%  -54.29% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Metric_starting_with_digit-2                 76.00 ± 0%   40.00 ± 0%  -47.37% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Metric_with_multiple_underscores-2          221.00 ± 0%   96.00 ± 0%  -56.56% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Metric_with_complex_unit-2                   96.00 ± 0%   48.00 ± 0%  -50.00% (p=0.002 n=6)
geomean                                                                                  159.6        100.1       -37.29%

                                                                                      │  main.txt   │           no-regexp.txt           │
                                                                                      │  allocs/op  │ allocs/op   vs base               │
BuildCompliantMetricName/withSuffixes=true/Basic_metric_with_no_special_characters-2     6.000 ± 0%   4.000 ± 0%  -33.33% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Counter_metric-2                              8.000 ± 0%   6.000 ± 0%  -25.00% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Gauge_ratio_metric-2                          7.000 ± 0%   5.000 ± 0%  -28.57% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Metric_with_per-unit_suffix_notation-2       10.000 ± 0%   7.000 ± 0%  -30.00% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Metric_with_special_characters-2              6.000 ± 0%   4.000 ± 0%  -33.33% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Metric_starting_with_digit-2                  6.000 ± 0%   4.000 ± 0%  -33.33% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Metric_with_multiple_underscores-2            6.000 ± 0%   4.000 ± 0%  -33.33% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=true/Metric_with_complex_unit-2                   12.000 ± 0%   8.000 ± 0%  -33.33% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Basic_metric_with_no_special_characters-2   15.000 ± 0%   2.000 ± 0%  -86.67% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Counter_metric-2                            16.000 ± 0%   2.000 ± 0%  -87.50% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Gauge_ratio_metric-2                        14.000 ± 0%   2.000 ± 0%  -85.71% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Metric_with_per-unit_suffix_notation-2      10.000 ± 0%   2.000 ± 0%  -80.00% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Metric_with_special_characters-2            28.000 ± 0%   3.000 ± 0%  -89.29% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Metric_starting_with_digit-2                11.000 ± 0%   2.000 ± 0%  -81.82% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Metric_with_multiple_underscores-2          37.000 ± 0%   2.000 ± 0%  -94.59% (p=0.002 n=6)
BuildCompliantMetricName/withSuffixes=false/Metric_with_complex_unit-2                  14.000 ± 0%   2.000 ± 0%  -85.71% (p=0.002 n=6)
geomean

…cores between words into single one

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
@ArthurSens
Copy link
Member Author

Oh my gosh I just realized I benchmarked the wrong function 🤦. I'll get back to this later

@ArthurSens
Copy link
Member Author

Ok, description updated with the correct benchmark results

Copy link
Contributor

@aknuds1 aknuds1 left a comment

Choose a reason for hiding this comment

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

If you want to include changes from #20 in this PR, it should be in draft mode and not considered for merging until #20 is approved and merged.

It would be better if this optimization PR would be independent of #20, and free of functionality changes.

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