Skip to content

Simplify label boundary detection in sample parser#1182

Open
afrkorsakow wants to merge 1 commit into
prometheus:masterfrom
afrkorsakow:feature/perfome
Open

Simplify label boundary detection in sample parser#1182
afrkorsakow wants to merge 1 commit into
prometheus:masterfrom
afrkorsakow:feature/perfome

Conversation

@afrkorsakow

Copy link
Copy Markdown

Optimize line parsing by using str.find() for locating { and str.rfind() for location }

Since metric names cannnot contain { and values are always numeric, escape handling is entirely unnecessary for bounday detection. This imporvemnt scales with line length.

benchmark

git switch master
pytest tests/test_parser.py  --benchmark-only --benchmark-save master
git switch feature/performe
pytest tests/test_parser.py  --benchmark-only --benchmark-compare 0002_master
----------------------------------------------------------------------------------------------------------- benchmark: 2 tests -----------------------------------------------------------------------------------------------------------
Name (time in us)                                                    Min                 Max                Mean             StdDev              Median                IQR            Outliers  OPS (Kops/s)            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_benchmark_text_string_to_metric_families (NOW)             115.9000 (1.0)      205.4800 (1.0)      128.7905 (1.0)      13.6625 (1.0)      123.5150 (1.0)       9.7862 (1.0)       438;402        7.7645 (1.0)        3587           1
test_benchmark_text_string_to_metric_families (0002_master)     147.6700 (1.27)     319.5870 (1.56)     168.5964 (1.31)     18.2601 (1.34)     161.9480 (1.31)     14.6172 (1.49)      480;383        5.9313 (0.76)       3373           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Signed-off-by: afrkorsakow <afrkorsakow@gmail.com>

@csmarchbanks csmarchbanks 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.

Thanks!

With the new UTF-8 support there can be escaped braces in a metric name. I think that means this cannot be done as it could find a set of labels mid-metric and then error. We should probably add a test case for that to make sure however, and it is definitely possible we could continue to optimize the parser performance.

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