Skip to content

Commit

Permalink
add HERTZ_EXP_FASTGO_ENABLE environment variable to enable fastgo
Browse files Browse the repository at this point in the history
comopression and decompression

Signed-off-by: TangYang <yang.tang@intel.com>
  • Loading branch information
cocotyty committed May 28, 2024
1 parent 533b7cc commit 206ff96
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/common/compress/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import (
"compress/gzip"
"fmt"
"io"
"os"
"strconv"
"sync"

"github.com/intel/fastgo"
Expand All @@ -57,6 +59,14 @@ import (
"github.com/cloudwego/hertz/pkg/network"
)

var fastgoEnable bool

func init() {
if fastgo.Optimized() {
fastgoEnable, _ = strconv.ParseBool(os.Getenv("HERTZ_EXP_FASTGO_ENABLE"))
}
}

const CompressDefaultCompression = 6 // flate.DefaultCompression

var (
Expand Down Expand Up @@ -144,7 +154,7 @@ func (r *byteSliceReader) Read(p []byte) (int, error) {
func acquireGzipReader(r io.Reader) (Reader, error) {
v := readerPool.Get()
if v == nil {
if fastgo.Optimized() {
if fastgoEnable {
return igzip.NewReader(r)
}

Expand Down Expand Up @@ -228,7 +238,7 @@ func acquireRealGzipWriter(w io.Writer, level int) Writer {
if v == nil {
var zw Writer
var err error
if fastgo.Optimized() && level <= 2 {
if fastgoEnable && level <= 2 {
zw, err = igzip.NewWriterLevel(w, level)
} else {
zw, err = gzip.NewWriterLevel(w, level)
Expand Down

0 comments on commit 206ff96

Please sign in to comment.