Skip to content

Commit

Permalink
refactor(sql): optimize protobuf marshalling methods
Browse files Browse the repository at this point in the history
Replaced `proto` methods with `VT` for better performance. Now, it's faster than your morning coffee!
  • Loading branch information
madflojo committed Oct 13, 2024
1 parent 31e86ea commit c76f747
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion testdata/base/sql/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ require (
github.com/tarmac-project/protobuf-go v0.0.0-20241006222641-e31a4349f2b8
github.com/tarmac-project/tarmac/pkg/sdk v0.5.0
github.com/wapc/wapc-guest-tinygo v0.3.3
google.golang.org/protobuf v1.35.1
)

require (
github.com/planetscale/vtprotobuf v0.6.0 // indirect
github.com/valyala/fastjson v1.6.4 // indirect
google.golang.org/protobuf v1.35.1 // indirect
)
5 changes: 2 additions & 3 deletions testdata/base/sql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
wapc "github.com/wapc/wapc-guest-tinygo"

"github.com/tarmac-project/protobuf-go/sdk/sql"
pb "google.golang.org/protobuf/proto"
)

var tarmac *sdk.Tarmac
Expand All @@ -26,7 +25,7 @@ func main() {
func Handler(payload []byte) ([]byte, error) {
// Create SQL Request
query := &sql.SQLQuery{Query: []byte(`CREATE TABLE IF NOT EXISTS wasmguest ( id int NOT NULL, name varchar(255), PRIMARY KEY (id) );`)}
q, err := pb.Marshal(query)
q, err := query.MarshalVT()
if err != nil {
tarmac.Logger.Error(fmt.Sprintf("Unable to marshal SQL query - %s", err))
return []byte(""), fmt.Errorf(`Failed to marshal SQL query - %s`, err)
Expand All @@ -41,7 +40,7 @@ func Handler(payload []byte) ([]byte, error) {

// Unmarshal the response
var response sql.SQLQueryResponse
err = pb.Unmarshal(rsp, &response)
err = response.UnmarshalVT(rsp)
if err != nil {
tarmac.Logger.Error(fmt.Sprintf("Unable to unmarshal SQL response - %s", err))
return []byte(""), fmt.Errorf(`Failed to unmarshal SQL response - %s`, err)
Expand Down

0 comments on commit c76f747

Please sign in to comment.