mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-13 15:46:49 +03:00
Lazy load stackless functions (#1656)
- I noticed that fasthttp was taking up 1.8MB of heap memory, even though it wasn't being used. This turned out to be the stackless function: 1.80MB github.com/valyala/fasthttp/stackless.NewFunc - Lazy load the stackless functions with sync.Once, given this a simple atomic read, it shouldn't affect performance for the fast-path (I haven't seen benchmarks with compression enabled).
This commit is contained in:
+12
-1
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"sync"
|
||||
|
||||
"github.com/valyala/bytebufferpool"
|
||||
)
|
||||
@@ -98,7 +99,17 @@ func (w *writer) do(op op) error {
|
||||
|
||||
var errHighLoad = errors.New("cannot compress data due to high load")
|
||||
|
||||
var stacklessWriterFunc = NewFunc(writerFunc)
|
||||
var (
|
||||
stacklessWriterFuncOnce sync.Once
|
||||
stacklessWriterFuncFunc func(ctx interface{}) bool
|
||||
)
|
||||
|
||||
func stacklessWriterFunc(ctx interface{}) bool {
|
||||
stacklessWriterFuncOnce.Do(func() {
|
||||
stacklessWriterFuncFunc = NewFunc(writerFunc)
|
||||
})
|
||||
return stacklessWriterFuncFunc(ctx)
|
||||
}
|
||||
|
||||
func writerFunc(ctx interface{}) {
|
||||
w := ctx.(*writer)
|
||||
|
||||
Reference in New Issue
Block a user