Skip to content

Commit 206ff96

Browse files
committed
add HERTZ_EXP_FASTGO_ENABLE environment variable to enable fastgo
comopression and decompression Signed-off-by: TangYang <[email protected]>
1 parent 533b7cc commit 206ff96

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

pkg/common/compress/compress.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ import (
4646
"compress/gzip"
4747
"fmt"
4848
"io"
49+
"os"
50+
"strconv"
4951
"sync"
5052

5153
"github.com/intel/fastgo"
@@ -57,6 +59,14 @@ import (
5759
"github.com/cloudwego/hertz/pkg/network"
5860
)
5961

62+
var fastgoEnable bool
63+
64+
func init() {
65+
if fastgo.Optimized() {
66+
fastgoEnable, _ = strconv.ParseBool(os.Getenv("HERTZ_EXP_FASTGO_ENABLE"))
67+
}
68+
}
69+
6070
const CompressDefaultCompression = 6 // flate.DefaultCompression
6171

6272
var (
@@ -144,7 +154,7 @@ func (r *byteSliceReader) Read(p []byte) (int, error) {
144154
func acquireGzipReader(r io.Reader) (Reader, error) {
145155
v := readerPool.Get()
146156
if v == nil {
147-
if fastgo.Optimized() {
157+
if fastgoEnable {
148158
return igzip.NewReader(r)
149159
}
150160

@@ -228,7 +238,7 @@ func acquireRealGzipWriter(w io.Writer, level int) Writer {
228238
if v == nil {
229239
var zw Writer
230240
var err error
231-
if fastgo.Optimized() && level <= 2 {
241+
if fastgoEnable && level <= 2 {
232242
zw, err = igzip.NewWriterLevel(w, level)
233243
} else {
234244
zw, err = gzip.NewWriterLevel(w, level)

0 commit comments

Comments
 (0)