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

Reduce allocations #1

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Reduce allocations #1

wants to merge 3 commits into from

Conversation

skr1n
Copy link

@skr1n skr1n commented Dec 24, 2021

Describe your change

Replace io.ReadAll + json.Unmarhal with json.NewDecoder
Added new SearchTyped method to serialize hits to user defined type instead of intermediate map[string]interface{}

What problem is this fixing?

Reducing memory allocations

goos: darwin
goarch: arm64
pkg: github.com/FindHotel/sapi-backend/internal/hotel
BenchmarkGeoSearch/Typed-8                   393           2966783 ns/op         1779498 B/op      13271 allocs/op
BenchmarkGeoSearch/NonTyped-8                201           5796816 ns/op         3198823 B/op      33436 allocs/op
BenchmarkGeoSearch/NonTypedRA-8              208           5754820 ns/op         4127025 B/op      33450 allocs/op
PASS
ok      github.com/FindHotel/sapi-backend/internal/hotel        5.167s

Typed - version with typed response and json decoder
NonTyped - version with json decoder
NonTypedRA - version with io.ReadAll + json.Unmarshal

skr1n added 3 commits December 24, 2021 16:12
Replace json.Unmarshal with json.NewDecoder.
This reverts commit 4b66aa7.
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.

1 participant