Skip to content

Reduce allocations#1

Draft
skr1n wants to merge 3 commits intomasterfrom
reduce-allocations
Draft

Reduce allocations#1
skr1n wants to merge 3 commits intomasterfrom
reduce-allocations

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