diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9d53f4c..da72190 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,7 +3,7 @@ name: Tests on: [ push, pull_request ] jobs: - compatibility-test-amd64: + unittest-amd64: strategy: matrix: go: [ "1.18", "1.19", "1.20", "1.21", "1.22", "1.23" ] @@ -23,7 +23,7 @@ jobs: - name: Test Benchmark run: go test -bench=. -benchmem -run=none ./... -benchtime=100ms - compatibility-test-arm64: + unittest-arm64: strategy: matrix: go: [ "1.18", "1.19", "1.20", "1.21", "1.22", "1.23" ] @@ -42,3 +42,21 @@ jobs: run: cd tests && go test -race - name: Test Benchmark run: go test -bench=. -benchmem -run=none ./internal/reflect -benchtime=100ms + + buildtag-amd64: + strategy: + matrix: + go: [ "1.18", "1.23" ] + os: [ X64 ] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + cache: false # don't use cache for self-hosted runners + - name: Build without frugal_jit + run: go build -v ./... + - name: Build with frugal_jit + run: go build -v -tags=frugal_jit ./... diff --git a/debug/debug_jit.go b/debug/debug_jit.go index 51e68c1..3af3221 100644 --- a/debug/debug_jit.go +++ b/debug/debug_jit.go @@ -1,4 +1,4 @@ -//go:build !go1.24 && amd64 && !windows +//go:build frugal_jit /* * Copyright 2022 CloudWeGo Authors diff --git a/debug/debug_go124.go b/debug/debug_nojit.go similarity index 94% rename from debug/debug_go124.go rename to debug/debug_nojit.go index 247cf32..6a67477 100644 --- a/debug/debug_go124.go +++ b/debug/debug_nojit.go @@ -1,4 +1,4 @@ -//go:build go1.24 || !amd64 || windows +//go:build !frugal_jit /* * Copyright 2024 CloudWeGo Authors diff --git a/frugal.go b/frugal.go index 7f26996..320c0c8 100644 --- a/frugal.go +++ b/frugal.go @@ -19,14 +19,13 @@ package frugal import ( "fmt" - "github.com/cloudwego/frugal/internal/opts" "github.com/cloudwego/frugal/internal/reflect" "github.com/cloudwego/gopkg/protocol/thrift" ) // EncodedSize measures the encoded size of val. func EncodedSize(val interface{}) int { - if !jit || opts.NoJIT { + if nojit { return reflect.EncodedSize(val) } return jitEncodedSize(val) @@ -35,7 +34,7 @@ func EncodedSize(val interface{}) int { // EncodeObject serializes val into buf with Thrift Binary Protocol, with optional Zero-Copy thrift.NocopyWriter. // buf must be large enough to contain the entire serialization result. func EncodeObject(buf []byte, w thrift.NocopyWriter, val interface{}) (int, error) { - if !jit || opts.NoJIT { + if nojit { ret, err := reflect.Append(buf[:0], val) if len(ret) > len(buf) { return 0, fmt.Errorf("index out of range [%d] with length %d.\n"+ @@ -49,7 +48,7 @@ func EncodeObject(buf []byte, w thrift.NocopyWriter, val interface{}) (int, erro // DecodeObject deserializes buf into val with Thrift Binary Protocol. func DecodeObject(buf []byte, val interface{}) (int, error) { - if !jit || opts.NoJIT { + if nojit { return reflect.Decode(buf, val) } return jitDecodeObject(buf, val) diff --git a/frugal_jit.go b/frugal_jit.go index 2f46a13..83c16a9 100644 --- a/frugal_jit.go +++ b/frugal_jit.go @@ -1,4 +1,4 @@ -//go:build !go1.24 && amd64 && !windows +//go:build frugal_jit /* * Copyright 2024 CloudWeGo Authors @@ -20,17 +20,15 @@ package frugal import ( "reflect" - "sync" + "github.com/cloudwego/frugal/internal/jit" "github.com/cloudwego/frugal/internal/jit/decoder" "github.com/cloudwego/frugal/internal/jit/encoder" - "github.com/cloudwego/frugal/internal/jit/rt" - "github.com/cloudwego/frugal/internal/jit/utils" "github.com/cloudwego/frugal/internal/opts" "github.com/cloudwego/gopkg/protocol/thrift" ) -const jit = true +const nojit = false func jitEncodedSize(val interface{}) int { return encoder.EncodedSize(val) @@ -44,79 +42,10 @@ func jitDecodeObject(buf []byte, val interface{}) (int, error) { return decoder.DecodeObject(buf, val) } -type _Ty struct { - d int - ty *rt.GoType -} - -var ( - typool sync.Pool -) - -func newty(ty *rt.GoType, d int) *_Ty { - if v := typool.Get(); v == nil { - return &_Ty{d, ty} - } else { - r := v.(*_Ty) - r.d, r.ty = d, ty - return r - } -} - -// Pretouch compiles vt ahead-of-time to avoid JIT compilation on-the-fly, in -// order to reduce the first-hit latency. func Pretouch(vt reflect.Type, options ...Option) error { - if opts.NoJIT { - return nil - } - d := 0 o := opts.GetDefaultOptions() - - /* apply all the options */ for _, fn := range options { fn(&o) } - - /* unpack the type */ - v := make(map[*rt.GoType]bool) - t := rt.Dereference(rt.UnpackType(vt)) - - /* add the root type */ - q := utils.NewQueue() - q.Enqueue(newty(t, 1)) - - /* BFS the type tree */ - for !q.Empty() { - ty := q.Dequeue().(*_Ty) - tv, err := decoder.Pretouch(ty.ty, o) - - /* also pretouch the encoder */ - if err == nil { - err = encoder.Pretouch(ty.ty, o) - } - - /* mark the type as been visited */ - d, v[ty.ty] = ty.d, true - typool.Put(ty) - - /* check for errors */ - if err != nil { - return err - } - - /* check for cutoff conditions */ - if !o.CanPretouch(d) { - continue - } - - /* add all the not visited sub-types */ - for s := range tv { - if t = rt.UnpackType(s); !v[t] { - q.Enqueue(newty(t, d+1)) - } - } - } - - /* completed with no errors */ - return nil + return jit.Pretouch(vt, o) } diff --git a/frugal_jit_go124.go b/frugal_nojit.go similarity index 74% rename from frugal_jit_go124.go rename to frugal_nojit.go index b90db67..83985f9 100644 --- a/frugal_jit_go124.go +++ b/frugal_nojit.go @@ -1,4 +1,4 @@ -//go:build go1.24 || !amd64 || windows +//go:build !frugal_jit /* * Copyright 2024 CloudWeGo Authors @@ -21,27 +21,21 @@ package frugal import ( "reflect" - "github.com/cloudwego/frugal/internal/opts" "github.com/cloudwego/gopkg/protocol/thrift" ) -const jit = false // not implemented for go1.24 || !amd64 || windows - -func init() { - // force set opts.NoJIT true coz jit not available - opts.NoJIT = true -} +const nojit = true func jitEncodedSize(val interface{}) int { - panic("not support JIT for Go version >= go1.24") + panic("not supported") } func jitEncodeObject(buf []byte, w thrift.NocopyWriter, val interface{}) (int, error) { - panic("not support JIT for Go version >= go1.24") + panic("not supported") } func jitDecodeObject(buf []byte, val interface{}) (int, error) { - panic("not support JIT for Go version >= go1.24") + panic("not supported") } // Pretouch compiles vt ahead-of-time to avoid JIT compilation on-the-fly, in diff --git a/go.sum b/go.sum index 7d66818..d0e577e 100644 --- a/go.sum +++ b/go.sum @@ -12,74 +12,19 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8Yc github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/arch v0.2.0 h1:W1sUEHXiJTfjaFJ5SLo0N6lZn+0eO5gWD1MFeTGqQEY= golang.org/x/arch v0.2.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= -golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= -golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= -rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/internal/jit/jit.go b/internal/jit/jit.go new file mode 100644 index 0000000..00c1ad5 --- /dev/null +++ b/internal/jit/jit.go @@ -0,0 +1,96 @@ +/* + * Copyright 2025 CloudWeGo Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package jit + +import ( + "reflect" + "sync" + + "github.com/cloudwego/frugal/internal/jit/decoder" + "github.com/cloudwego/frugal/internal/jit/encoder" + "github.com/cloudwego/frugal/internal/jit/rt" + "github.com/cloudwego/frugal/internal/jit/utils" + "github.com/cloudwego/frugal/internal/opts" +) + +type _Ty struct { + d int + ty *rt.GoType +} + +var ( + typool sync.Pool +) + +func newty(ty *rt.GoType, d int) *_Ty { + if v := typool.Get(); v == nil { + return &_Ty{d, ty} + } else { + r := v.(*_Ty) + r.d, r.ty = d, ty + return r + } +} + +// Pretouch compiles vt ahead-of-time to avoid JIT compilation on-the-fly, in +// order to reduce the first-hit latency. +func Pretouch(vt reflect.Type, o opts.Options) error { + d := 0 + + /* unpack the type */ + v := make(map[*rt.GoType]bool) + t := rt.Dereference(rt.UnpackType(vt)) + + /* add the root type */ + q := utils.NewQueue() + q.Enqueue(newty(t, 1)) + + /* BFS the type tree */ + for !q.Empty() { + ty := q.Dequeue().(*_Ty) + tv, err := decoder.Pretouch(ty.ty, o) + + /* also pretouch the encoder */ + if err == nil { + err = encoder.Pretouch(ty.ty, o) + } + + /* mark the type as been visited */ + d, v[ty.ty] = ty.d, true + typool.Put(ty) + + /* check for errors */ + if err != nil { + return err + } + + /* check for cutoff conditions */ + if !o.CanPretouch(d) { + continue + } + + /* add all the not visited sub-types */ + for s := range tv { + if t = rt.UnpackType(s); !v[t] { + q.Enqueue(newty(t, d+1)) + } + } + } + + /* completed with no errors */ + return nil +} diff --git a/options.go b/options.go index e5a875b..6344e6e 100644 --- a/options.go +++ b/options.go @@ -28,8 +28,19 @@ type Option func(*opts.Options) // NoJIT disables JIT encoder and decoder explicitly. // // This function will be deprecated along with the JIT implementation in the future. +// +// Deprecated: JIT is disabled by default. func NoJIT(v bool) { opts.NoJIT = v + + println(` +frugal.NoJIT is deprecated. JIT is disabled by default since v0.2.4. +If you still want to use JIT, please specify frugal_jit tag for go build to enable it. + +Please do note that: +The JIT implementation is no longer maintained, +DO NOT submit any issues or pull requests. +`) } const ( @@ -45,6 +56,8 @@ const ( // Set this option to "0" disables this limit, which means inlining everything. // // The default value of this option is "2". +// +// Deprecated: only for JIT func WithMaxInlineDepth(depth int) Option { if depth < 0 { panic(fmt.Sprintf("frugal: invalid inline depth: %d", depth)) @@ -63,6 +76,8 @@ func WithMaxInlineDepth(depth int) Option { // IL buffer. // // The default value of this option is "50000". +// +// Deprecated: only for JIT func WithMaxInlineILSize(size int) Option { if size != 0 && size < _MinILSize { panic(fmt.Sprintf("frugal: invalid inline IL size: %d", size)) @@ -84,6 +99,8 @@ func WithMaxInlineILSize(size int) Option { // // This option is only available when performing pretouch, otherwise it is // ignored and do not have any effect. +// +// Deprecated: only for JIT func WithMaxPretouchDepth(depth int) Option { if depth < 0 { panic(fmt.Sprintf("frugal: invalid pretouch depth: %d", depth)) @@ -101,6 +118,8 @@ func WithMaxPretouchDepth(depth int) Option { // The default value of this option is "2". // // Returns the old opts.MaxInlineDepth value. +// +// Deprecated: only for JIT func SetMaxInlineDepth(depth int) int { depth, opts.MaxInlineDepth = opts.MaxInlineDepth, depth return depth @@ -115,6 +134,8 @@ func SetMaxInlineDepth(depth int) int { // The default value of this option is "50000". // // Returns the old opts.MaxInlineILSize value. +// +// Deprecated: only for JIT func SetMaxInlineILSize(size int) int { size, opts.MaxInlineILSize = opts.MaxInlineILSize, size return size diff --git a/tests/allsize_test.go b/tests/allsize_test.go index 28ad34c..dda5157 100644 --- a/tests/allsize_test.go +++ b/tests/allsize_test.go @@ -31,9 +31,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/cloudwego/frugal" + "github.com/cloudwego/frugal/internal/opts" freflect "github.com/cloudwego/frugal/internal/reflect" gthrift "github.com/cloudwego/gopkg/protocol/thrift" + + "github.com/cloudwego/frugal/internal/jit" + jitDecoder "github.com/cloudwego/frugal/internal/jit/decoder" + jitEncoder "github.com/cloudwego/frugal/internal/jit/encoder" ) func TestMain(m *testing.M) { @@ -193,10 +197,10 @@ func BenchmarkAllSize_BLength_Frugal_JIT(b *testing.B) { b.Run(s.name, func(b *testing.B) { b.SetBytes(int64(len(s.bytes))) v := s.val - assert.Equal(b, frugal.EncodedSize(v), len(s.bytes)) + assert.Equal(b, jitEncoder.EncodedSize(v), len(s.bytes)) b.ResetTimer() for i := 0; i < b.N; i++ { - frugal.EncodedSize(v) + jitEncoder.EncodedSize(v) } }) } @@ -254,15 +258,15 @@ func BenchmarkAllSize_Marshal_Frugal_JIT(b *testing.B) { b.Run(s.name, func(b *testing.B) { b.SetBytes(int64(len(s.bytes))) v := s.val - buf := make([]byte, frugal.EncodedSize(v)) - n, err := frugal.EncodeObject(buf, nil, v) + buf := make([]byte, jitEncoder.EncodedSize(v)) + n, err := jitEncoder.EncodeObject(buf, nil, v) require.NoError(b, err) require.Equal(b, len(buf), n) assert.Equal(b, len(s.bytes), n) b.ResetTimer() for i := 0; i < b.N; i++ { - _ = frugal.EncodedSize(v) - _, _ = frugal.EncodeObject(buf, nil, v) + _ = jitEncoder.EncodedSize(v) + _, _ = jitEncoder.EncodeObject(buf, nil, v) } }) } @@ -343,13 +347,13 @@ func BenchmarkAllSize_Unmarshal_Frugal_JIT(b *testing.B) { b.SetBytes(int64(len(s.bytes))) buf := s.bytes v := newByEFace(s.val) - n, err := frugal.DecodeObject(buf, v) + n, err := jitDecoder.DecodeObject(buf, v) require.NoError(b, err) require.Equal(b, len(buf), n) b.ResetTimer() for i := 0; i < b.N; i++ { objectmemclr(v) - _, _ = frugal.DecodeObject(buf, v) + _, _ = jitDecoder.DecodeObject(buf, v) } }) } @@ -410,15 +414,15 @@ func BenchmarkAllSize_Parallel_Marshal_FastCodec(b *testing.B) { func BenchmarkAllSize_Parallel_Marshal_Frugal_JIT(b *testing.B) { for _, s := range getSamples() { b.Run(s.name, func(b *testing.B) { - frugal.Pretouch(reflect.TypeOf(s.val)) + jit.Pretouch(reflect.TypeOf(s.val), opts.GetDefaultOptions()) b.SetBytes(int64(len(s.bytes))) b.ResetTimer() b.RunParallel(func(pb *testing.PB) { v := s.val - buf := make([]byte, frugal.EncodedSize(v)) + buf := make([]byte, jitEncoder.EncodedSize(v)) for pb.Next() { - frugal.EncodedSize(v) - _, _ = frugal.EncodeObject(buf, nil, v) + jitEncoder.EncodedSize(v) + _, _ = jitEncoder.EncodeObject(buf, nil, v) } }) }) @@ -481,7 +485,7 @@ func BenchmarkAllSize_Parallel_Unmarshal_FastCodec(b *testing.B) { func BenchmarkAllSize_Parallel_Unmarshal_Frugal_JIT(b *testing.B) { for _, s := range getSamples() { b.Run(s.name, func(b *testing.B) { - frugal.Pretouch(reflect.TypeOf(s.val)) + jit.Pretouch(reflect.TypeOf(s.val), opts.GetDefaultOptions()) b.SetBytes(int64(len(s.bytes))) buf := s.bytes b.ResetTimer() @@ -489,7 +493,7 @@ func BenchmarkAllSize_Parallel_Unmarshal_Frugal_JIT(b *testing.B) { v := newByEFace(s.val) for pb.Next() { objectmemclr(v) - _, _ = frugal.DecodeObject(buf, v) + _, _ = jitDecoder.DecodeObject(buf, v) } }) })