Skip to content
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

Perf improvements in HTTP protocol #444

Merged

Conversation

slinkydeveloper
Copy link
Member

Because net/http.Header states that headers are keyed by their canonical mime header representation (https://golang.org/pkg/net/http/#Header), I optimized on avoiding any middle allocations for accessing the attributes map and i pre-compute the header names for the various attributes.

I've also rewrote the computation of the extension key, in order to allocate only one new string.

Results

benchmark                                   old ns/op     new ns/op     delta
BenchmarkHttpWithToEvent-8                  17220         15179         -11.85%
BenchmarkNoDataHttpWithToEvent-8            16575         14101         -14.93%
BenchmarkHttpWithBuffering-8                10642         8703          -18.22%
BenchmarkHttpWithDirect-8                   9080          7613          -16.16%
BenchmarkNoDataHttpWithBuffering-8          10041         8613          -14.22%
BenchmarkNoDataHttpWithDirect-8             9225          7785          -15.61%

benchmark                                   old allocs     new allocs     delta
BenchmarkHttpWithToEvent-8                  136            108            -20.59%
BenchmarkNoDataHttpWithToEvent-8            130            102            -21.54%
BenchmarkHttpWithBuffering-8                108            80             -25.93%
BenchmarkHttpWithDirect-8                   101            73             -27.72%
BenchmarkNoDataHttpWithBuffering-8          106            78             -26.42%
BenchmarkNoDataHttpWithDirect-8             99             71             -28.28%

benchmark                                   old bytes     new bytes     delta
BenchmarkHttpWithToEvent-8                  8385          8061          -3.86%
BenchmarkNoDataHttpWithToEvent-8            7759          7430          -4.24%
BenchmarkHttpWithBuffering-8                5816          5498          -5.47%
BenchmarkHttpWithDirect-8                   4502          4173          -7.31%
BenchmarkNoDataHttpWithBuffering-8          5777          5460          -5.49%
BenchmarkNoDataHttpWithDirect-8             4467          4151          -7.07%

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

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

Microoptimizations are fun! I like :)

require.Equal(t, e.ID(), sv.Attribute("Ce-Id").Get(e.Context))
require.Equal(t, "id", sv.Attribute("Ce-Id").Name())

require.Equal(t, e.DataContentType(), sv.Attribute("Content-Type").Get(e.Context))
Copy link
Member

Choose a reason for hiding this comment

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

This is only true for binary mode.

Copy link
Member Author

Choose a reason for hiding this comment

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

I know that, Version and related interfaces are used only for binary messages

@n3wscott
Copy link
Member

n3wscott commented Apr 7, 2020

LGTM

@slinkydeveloper slinkydeveloper merged commit 6c21831 into cloudevents:master Apr 7, 2020
@slinkydeveloper slinkydeveloper deleted the trying_to_gain_cpu_cycles branch April 7, 2020 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants