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

Removed perf regression on format.Lookup #503

Merged

Conversation

slinkydeveloper
Copy link
Member

@slinkydeveloper slinkydeveloper commented May 13, 2020

Fixes #494

Removed usage of mime.ParseMediaType(contentType) since it's quite expensive and we discard all the results except the first part. Part of the code is took from ParseMediaType directly

Now results are back to the previous values:

(c875624)⚡ % go test -benchmem -bench  . ./...
goos: linux
goarch: amd64
pkg: github.com/cloudevents/sdk-go/v2/protocol/kafka_sarama
BenchmarkNewStructuredMessage-8          	 3852535	       324 ns/op	     528 B/op	       5 allocs/op
BenchmarkNewBinaryMessage-8              	 1000000	      1033 ns/op	     953 B/op	      12 allocs/op
BenchmarkNewStructuredMessageToEvent-8   	   36049	     30915 ns/op	   11007 B/op	     171 allocs/op
BenchmarkNewBinaryMessageToEvent-8       	  279211	      4595 ns/op	    2701 B/op	      44 allocs/op
BenchmarkEncodeStructuredMessage-8       	 2668867	       485 ns/op	     768 B/op	       8 allocs/op
BenchmarkEncodeBinaryMessage-8           	  293518	      3889 ns/op	    2608 B/op	      47 allocs/op
PASS
ok  	github.com/cloudevents/sdk-go/v2/protocol/kafka_sarama	8.327s
(c875624)⚡ % go test -benchmem -bench  . ./...                                                                                                                                ~/go/src/github.com/cloudevents/sdk-go/v2/protocol/kafka_sarama
(c875624)⚡ [130] % git checkout remove_parse_media_type
(remove_parse_media_type) % go test -benchmem -bench  . ./...
goos: linux
goarch: amd64
pkg: github.com/cloudevents/sdk-go/v2/protocol/kafka_sarama
BenchmarkNewStructuredMessage-8          	 3656006	       340 ns/op	     528 B/op	       5 allocs/op
BenchmarkNewBinaryMessage-8              	 1000000	      1069 ns/op	     953 B/op	      12 allocs/op
BenchmarkNewStructuredMessageToEvent-8   	   38396	     31017 ns/op	   11007 B/op	     171 allocs/op
BenchmarkNewBinaryMessageToEvent-8       	  251192	      4607 ns/op	    2705 B/op	      44 allocs/op
BenchmarkEncodeStructuredMessage-8       	   32894	     37538 ns/op	   13511 B/op	     226 allocs/op
BenchmarkEncodeBinaryMessage-8           	  280929	      4264 ns/op	    2656 B/op	      50 allocs/op
PASS
ok  	github.com/cloudevents/sdk-go/v2/protocol/kafka_sarama	8.232s

Signed-off-by: Francesco Guardiani francescoguard@gmail.com

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
@slinkydeveloper slinkydeveloper requested a review from n3wscott May 13, 2020 12:28
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
Copy link
Member

@n3wscott n3wscott left a comment

Choose a reason for hiding this comment

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

LGTM

@slinkydeveloper slinkydeveloper merged commit 5f32742 into cloudevents:master May 13, 2020
@slinkydeveloper slinkydeveloper deleted the remove_parse_media_type branch May 13, 2020 14:21
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.

Performance regression in kafka_sarama.BenchmarkNewStructuredMessage
2 participants