fasthttp icon indicating copy to clipboard operation
fasthttp copied to clipboard

use buffer on response in clientDoDeadline

Open brian-armstrong-discord opened this issue 7 years ago • 3 comments

we want to do this so that we can reuse the response's existing buffer rather than allocating new ones. allocating memory is expensive

brian-armstrong-discord avatar May 09 '17 02:05 brian-armstrong-discord

isn't it doing that by default? the code as written prior seems to swap the body to reset it after an error occurs.. otherwise it is using the same

Edit: also worth noting that it shouldn't really be allocating unless it needs to.. it's pooling old buffers in http.go for reuse

night avatar May 09 '17 02:05 night

the key change is L921. L941 is just necessary in order to swap back.

not sure if this actually works - i havent quite got it to do the right thing in media proxy yet. but it does actually use my buffer now, whereas it didnt previously.

brian-armstrong-discord avatar May 09 '17 03:05 brian-armstrong-discord

also for clarity, in media proxy, fasthttp does not own the buffers, a different part of the server does. so we are in a bad situation because we fasthttp creates a ton of garbage and we have to copy out of its buffers. the idea here is to make fasthttp stop allocating entirely.

brian-armstrong-discord avatar May 09 '17 03:05 brian-armstrong-discord