Skip to content

perf: avoid closures that cause allocations#10

Merged
costela merged 3 commits intomainfrom
leo.antunes/few-performance-improvements
Nov 22, 2023
Merged

perf: avoid closures that cause allocations#10
costela merged 3 commits intomainfrom
leo.antunes/few-performance-improvements

Conversation

@costela
Copy link
Member

@costela costela commented Nov 20, 2023

This is a light improvement on allocations and performance:

pkg: github.com/exaring/hoglet
cpu: 12th Gen Intel(R) Core(TM) i7-1250U
                           │  old.bench   │              new.bench              │
                           │    sec/op    │    sec/op     vs base               │
Hoglet_Do_EWMA-12            409.7n ± 12%   376.9n ± 17%       ~ (p=0.075 n=10)
Hoglet_Do_SlidingWindow-12   463.2n ±  2%   453.3n ±  7%       ~ (p=0.149 n=10)
geomean                      435.6n         413.4n        -5.10%

                           │ old.bench  │             new.bench              │
                           │    B/op    │    B/op     vs base                │
Hoglet_Do_EWMA-12            240.0 ± 0%   208.0 ± 0%  -13.33% (p=0.000 n=10)
Hoglet_Do_SlidingWindow-12   240.0 ± 0%   208.0 ± 0%  -13.33% (p=0.000 n=10)
geomean                      240.0        208.0       -13.33%

                           │ old.bench  │             new.bench              │
                           │ allocs/op  │ allocs/op   vs base                │
Hoglet_Do_EWMA-12            6.000 ± 0%   5.000 ± 0%  -16.67% (p=0.000 n=10)
Hoglet_Do_SlidingWindow-12   6.000 ± 0%   5.000 ± 0%  -16.67% (p=0.000 n=10)
geomean                      6.000        5.000       -16.67%

Still some work to do. We should be able to get to 1-2 allocs per call.
I do not think zero allocations are possible as long as we have the asynchronous reactions to context deadlines/cancelations, since that needs sharing across goroutines.

@costela costela marked this pull request as ready for review November 21, 2023 07:05
Copy link
Member

@obitech obitech left a comment

Choose a reason for hiding this comment

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

LGTM

@costela costela merged commit aaac6de into main Nov 22, 2023
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

Comments