losvedir / transit-lang-cmp

Programming language comparison by reimplementing the same transit data app
MIT License
426 stars 31 forks source link

Go Response Writing Optimization #8

Open ryan-berger opened 2 years ago

ryan-berger commented 2 years ago

I noticed that here You call json.Marshal on the response, which would load the entire response in to memory before writing it out.

It may be a better idea to do:

err := json.NewEncoder(request.Body).Encode(&response)

This could improve memory consumption which could in-turn improve garbage collection performance. I'm not 100% sure on it though, just a thought