Skip to content

Commit

Permalink
Fix performance degradation while host functions call
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Volodin <dmvolod@gmail.com>
  • Loading branch information
dmvolod committed Apr 19, 2023
1 parent 898cc7b commit fb23714
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/host-function-library/proto/greet_plugin.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/host-functions/greeting/greet_plugin.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions gen/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func genHostFunctions(g *protogen.GeneratedFile, f *fileInfo) {
}
ptr, size := %s(buf)
ptrSize := _%s(ptr, size)
%s(ptr)
ptr = uint32(ptrSize >> 32)
size = uint32(ptrSize)
Expand All @@ -132,6 +133,7 @@ func genHostFunctions(g *protogen.GeneratedFile, f *fileInfo) {
g.QualifiedGoIdent(method.Output.GoIdent),
g.QualifiedGoIdent(pluginWasmPackage.Ident("ByteToPtr")),
importedName,
g.QualifiedGoIdent(pluginWasmPackage.Ident("FreePtr")),
g.QualifiedGoIdent(pluginWasmPackage.Ident("PtrToByte")),
g.QualifiedGoIdent(method.Output.GoIdent),
))
Expand Down
1 change: 1 addition & 0 deletions tests/host-functions/proto/host_plugin.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions wasm/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ func ByteToPtr(buf []byte) (uint32, uint32) {

return uint32(uintptr(ptr)), uint32(len(buf))
}

func FreePtr(ptr uint32) {
C.free(unsafe.Pointer(uintptr(ptr)))
}

0 comments on commit fb23714

Please sign in to comment.