fasthttp icon indicating copy to clipboard operation
fasthttp copied to clipboard

is there a way to change Response.Body() without memory copying?

Open hiqsociety opened this issue 2 years ago • 1 comments

i'm using minify https://github.com/tdewolff/minify to minify ctx.Response.Body() but trying to reduce GC pressure by doing arena but was wondering if i can just somehow modify the Response Body w/o mem copying... which will be better. is this possible?

mem := arena.NewArena()
o := arena.New[H](mem)

o.Data, o.Err = m.Bytes("text/html", ctx.Response.Body()) //minified here
if o.Err != nil {
	log.Printf("minify1 %s", o.Err)
} else {
	log.Printf("o.Data = %s", o.Data)
	ctx.Response.SetBody(o.Data)
}
ctx.Response.Header.SetStatusCode(200)
ctx.Response.Header.SetContentType("text/html")
mem.Free()

hiqsociety avatar Aug 01 '23 13:08 hiqsociety

Have you tried using Response.SetBodyRaw?

erikdubbelboer avatar Aug 01 '23 16:08 erikdubbelboer