Skip to content

Parse Durations much faster#461

Merged
roidelapluie merged 2 commits intoprometheus:mainfrom
bboreham:faster-parseduration
Mar 6, 2023
Merged

Parse Durations much faster#461
roidelapluie merged 2 commits intoprometheus:mainfrom
bboreham:faster-parseduration

Conversation

@bboreham
Copy link
Member

@bboreham bboreham commented Mar 6, 2023

Without using a regexp.

This shows up in profiles of Prometheus service discovery, since ParseDuration is called twice per discovered target.

name             old time/op    new time/op    delta
ParseDuration-4    2.54µs ±28%    0.04µs ± 3%   -98.30%  (p=0.008 n=5+5)

name             old alloc/op   new alloc/op   delta
ParseDuration-4      480B ± 0%        0B       -100.00%  (p=0.079 n=4+5)

name             old allocs/op  new allocs/op  delta
ParseDuration-4      2.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)

Code inspired by Go standard library time.ParseDuration, but simplified and supporting different units.

bboreham added 2 commits March 6, 2023 12:50
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Without using a regexp.

Code inspired by Go standard library `time.ParseDuration`, but
simplified and supporting different units.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
@roidelapluie roidelapluie merged commit d7d98af into prometheus:main Mar 6, 2023
@roidelapluie
Copy link
Member

Thanks!

@bboreham
Copy link
Member Author

bboreham commented Mar 7, 2023

Now I realise this makes one of the Prometheus tests fail due to changed error message:

--- FAIL: TestPopulateLabels (0.00s)
    manager_test.go:436: 
                Error Trace:    /home/vagrant/src/github.com/prometheus/prometheus/scrape/manager_test.go:436
                Error:          Error message not equal:
                                expected: "error parsing scrape interval: not a valid duration string: \"2notseconds\""
                                actual  : "error parsing scrape interval: unknown unit \"notseconds\" in duration \"2notseconds\""
                Test:           TestPopulateLabels

Do you think it's important to retain consistency of error messages? I.e. shall I fix it here or in the test?

@bboreham bboreham deleted the faster-parseduration branch March 27, 2023 16:29
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