Skip to content

Commit

Permalink
Merge pull request #164 from ymz-ncnk/master
Browse files Browse the repository at this point in the history
Update mus to v0.2.3, second attempt
  • Loading branch information
deneonet authored Jun 20, 2024
2 parents 7fa39ce + b82a42e commit d9b874e
Show file tree
Hide file tree
Showing 5 changed files with 359 additions and 364 deletions.
2 changes: 1 addition & 1 deletion benchmarks.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ var benchmarkCases = []BenchmarkCase{
}, {
Name: "mus/unsafe_reuse",
URL: "github.com/mus-format/mus-go",
New: mus.NewMUSUnsafeSerializer,
New: mus.NewMUSUnsafeReuseSerializer,

BufferReuseMarshal: true,
UnsafeStringUnmarshal: true,
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ require (
wellquite.org/bebop v0.0.0-20231109192402-a92af83691ec
)

require github.com/mus-format/common-go v0.0.0-20240427160332-fda7f59c1da2 // indirect

require (
github.com/DataDog/zstd v1.5.2 // indirect
github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31 // indirect
Expand All @@ -52,8 +54,7 @@ require (
github.com/minio/sha256-simd v0.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mus-format/mus-common-go v0.0.0-20230426111652-d1324c6517b3 // indirect
github.com/mus-format/mus-go v0.0.0-20230426134740-6572513fca3d
github.com/mus-format/mus-go v0.2.3
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/protolambda/zssz v0.1.1 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/mus-format/mus-common-go v0.0.0-20230426111652-d1324c6517b3 h1:iGDJid8cb5Yt/pa1M/JEMC8u+Zkzv3WU6AKNOHtY/14=
github.com/mus-format/mus-common-go v0.0.0-20230426111652-d1324c6517b3/go.mod h1:sL9Q5xrbsrFJ0WQRvf7/Ji1ljR3p8TrywHj0hQBscsc=
github.com/mus-format/mus-go v0.0.0-20230426134740-6572513fca3d h1:/FqtbOoougvCbsp769ZZxgN3Pj/fepBAr4ETQXM+uwQ=
github.com/mus-format/mus-go v0.0.0-20230426134740-6572513fca3d/go.mod h1:zdDnTFri6XqdQVRTE/HuGnmn+/3c3a0ODNUsw+9SXS8=
github.com/mus-format/common-go v0.0.0-20240427160332-fda7f59c1da2 h1:VlQlK11OtURHQ1VsdHcp9OFq56i8HEIHURgfEtP9Jek=
github.com/mus-format/common-go v0.0.0-20240427160332-fda7f59c1da2/go.mod h1:1hTb8w0YdSGIOU6wNY+e9uXnDZ9OQnUivNtd8cPSdoU=
github.com/mus-format/mus-go v0.2.3 h1:HZ4NqdThMV2js9/goQueFqxAHaMBZDGBPwOwFv5f3LA=
github.com/mus-format/mus-go v0.2.3/go.mod h1:uRQAo0t2WbvKZ9Iz5wdZV4s5eq1LsTS9dSizQeV9s+M=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nazarifard/fastape v0.0.0-20240611084216-abaecf150e5b h1:Roh7HBLqAxLpo/qxWztQlzt6QUBGTCX9AXxCaJf+pB8=
github.com/nazarifard/fastape v0.0.0-20240611084216-abaecf150e5b/go.mod h1:F54tpGg4uMgsYNUqD07iNENNGcS2GJobr+td/iZ5Xm4=
Expand Down Expand Up @@ -293,8 +293,8 @@ github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/ymz-ncnk/mok v0.1.0 h1:GwOBkbcg1pznoDVLcS5uc2lA5UyT5TktFm7L/kyQNKQ=
github.com/ymz-ncnk/mok v0.1.0/go.mod h1:ieogm8yEogRr2OSLelrB38i4ZAWSmGhizWj9UQKm6+0=
github.com/ymz-ncnk/mok v0.2.0 h1:4xOvkG0EXDlr05ZTSeRzM2q5mbyNbALRqRoI+cTwUyc=
github.com/ymz-ncnk/mok v0.2.0/go.mod h1:VDVVGULp0vdJeD27SgJghOFGyD7w3nX7SDh8TOlvIsY=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
68 changes: 31 additions & 37 deletions internal/serializers/mus/mus.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,33 @@ func (s MUSSerializer) Marshal(o interface{}) ([]byte, error) {

func (s MUSSerializer) Unmarshal(bs []byte, o interface{}) (err error) {
v := o.(*goserbench.SmallStruct)

var n int

v.Name, n, err = ord.UnmarshalString(bs)
if err != nil {
return
}
var n1 int
var bdayNano int64
bdayNano, n1, err = raw.UnmarshalInt64(bs[n:])
v.BirthDay = time.Unix(0, bdayNano)
var (
n1 int
birthDay64 int64
)
birthDay64, n1, err = raw.UnmarshalInt64(bs[n:])
n += n1
if err != nil {
return
}
v.BirthDay = time.Unix(0, birthDay64)
v.Phone, n1, err = ord.UnmarshalString(bs[n:])
n += n1
if err != nil {
return
}
var sibInt32 int32
sibInt32, n1, err = varint.UnmarshalInt32(bs[n:])
v.Siblings = int(sibInt32)
var siblings32 int32
siblings32, n1, err = varint.UnmarshalInt32(bs[n:])
n += n1
if err != nil {
return
}
v.Siblings = int(siblings32)
v.Spouse, n1, err = ord.UnmarshalBool(bs[n:])
n += n1
if err != nil {
Expand All @@ -73,56 +73,50 @@ func NewMUSSerializer() goserbench.Serializer {
return MUSSerializer{}
}

type MUSUnsafeSerializer struct {
type MUSUnsafeReuseSerializer struct {
buf []byte
}

func (s MUSUnsafeSerializer) Marshal(o interface{}) ([]byte, error) {
func (s MUSUnsafeReuseSerializer) Marshal(o interface{}) ([]byte, error) {
v := o.(*goserbench.SmallStruct)
n := unsafe.SizeString(v.Name)
n += unsafe.SizeInt64(v.BirthDay.UnixNano())
n += unsafe.SizeString(v.Phone)
n += unsafe.SizeInt32(int32(v.Siblings))
n += unsafe.SizeBool(v.Spouse)
n += unsafe.SizeFloat64(v.Money)
buf := s.buf[:n]
n = unsafe.MarshalString(v.Name, buf)
n += unsafe.MarshalInt64(v.BirthDay.UnixNano(), buf[n:])
n += unsafe.MarshalString(v.Phone, buf[n:])
n += unsafe.MarshalInt32(int32(v.Siblings), buf[n:])
n += unsafe.MarshalBool(v.Spouse, buf[n:])
unsafe.MarshalFloat64(v.Money, buf[n:])
return buf, nil
n := unsafe.MarshalString(v.Name, s.buf)
n += unsafe.MarshalInt64(v.BirthDay.UnixNano(), s.buf[n:])
n += unsafe.MarshalString(v.Phone, s.buf[n:])
n += unsafe.MarshalInt32(int32(v.Siblings), s.buf[n:])
n += unsafe.MarshalBool(v.Spouse, s.buf[n:])
n += unsafe.MarshalFloat64(v.Money, s.buf[n:])
return s.buf[:n], nil
}

func (s MUSUnsafeSerializer) Unmarshal(bs []byte, o interface{}) (err error) {
var n int
func (s MUSUnsafeReuseSerializer) Unmarshal(bs []byte, o interface{}) (err error) {
v := o.(*goserbench.SmallStruct)

var n int
v.Name, n, err = unsafe.UnmarshalString(bs)
if err != nil {
return
}
var n1 int
var bdayNano int64
bdayNano, n1, err = unsafe.UnmarshalInt64(bs[n:])
v.BirthDay = time.Unix(0, bdayNano)
var (
n1 int
birthDay64 int64
)
birthDay64, n1, err = unsafe.UnmarshalInt64(bs[n:])
n += n1
if err != nil {
return
}
v.BirthDay = time.Unix(0, birthDay64)
v.Phone, n1, err = unsafe.UnmarshalString(bs[n:])
n += n1
if err != nil {
return
}
var sibInt32 int32
sibInt32, n1, err = unsafe.UnmarshalInt32(bs[n:])
v.Siblings = int(sibInt32)
var siblings32 int32
siblings32, n1, err = unsafe.UnmarshalInt32(bs[n:])
n += n1
if err != nil {
return
}
v.Siblings = int(siblings32)
v.Spouse, n1, err = unsafe.UnmarshalBool(bs[n:])
n += n1
if err != nil {
Expand All @@ -133,6 +127,6 @@ func (s MUSUnsafeSerializer) Unmarshal(bs []byte, o interface{}) (err error) {
return
}

func NewMUSUnsafeSerializer() goserbench.Serializer {
return MUSUnsafeSerializer{buf: make([]byte, 1024)}
func NewMUSUnsafeReuseSerializer() goserbench.Serializer {
return MUSUnsafeReuseSerializer{buf: make([]byte, 1024)}
}
Loading

0 comments on commit d9b874e

Please sign in to comment.