-
Notifications
You must be signed in to change notification settings - Fork 881
Use wazero-based libpgquery wrapper in currently disabled environments #3027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
0bee534
f7c2c9c
bae1e3c
f223341
4009fa4
315cb5a
767e168
a608c49
ce0fa99
61e9a97
d12d574
e0af7a9
2d8bb69
80881e7
03709bb
918bcba
720d2f9
c2d0f1d
64078d7
1ee3272
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
// Currently requires cgo for wasmtime. | ||
//go:build cgo | ||
// +build cgo | ||
|
||
package main | ||
|
||
import ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//go:build !windows && cgo | ||
// +build !windows,cgo | ||
|
||
package postgresql | ||
|
||
import ( | ||
cgonodes "github.com/pganalyze/pg_query_go/v4" | ||
wasinodes "github.com/wasilibs/go-pgquery" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
func parseNodes(input string) (*wasinodes.ParseResult, error) { | ||
cgoRes, err := cgonodes.Parse(input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// It would be too tedious to maintain conversion logic in a way that | ||
// can target the two types from different packages despite being identical. | ||
// We go ahead and take a small performance hit by marshaling through | ||
// protobuf to unify the types. We must use the wasilibs version because | ||
// the upstream version requires cgo even when only accessing the proto. | ||
|
||
resBytes, err := proto.Marshal(cgoRes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the performance regression, protobuf marshaling is very fast and it's actually relatively common to do this sort of conversion in real code I've seen. But I will try to get go-pgquery to use the same parsetree type as upstream to be able to avoid it, hopefully that goes smoothly |
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var wasiRes wasinodes.ParseResult | ||
if err := proto.Unmarshal(resBytes, &wasiRes); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &wasiRes, nil | ||
} | ||
|
||
var Parse = parseNodes | ||
var Fingerprint = cgonodes.Fingerprint |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//go:build windows || !cgo | ||
// +build windows !cgo | ||
|
||
package postgresql | ||
|
||
import ( | ||
nodes "github.com/wasilibs/go-pgquery" | ||
) | ||
|
||
var parseNodes = nodes.Parse | ||
|
||
var Parse = parseNodes | ||
var Fingerprint = nodes.Fingerprint |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//go:build !windows && cgo | ||
// +build !windows,cgo | ||
|
||
package parser | ||
|
||
import "github.com/pganalyze/pg_query_go/v4/parser" | ||
|
||
type Error = parser.Error |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//go:build windows || !cgo | ||
// +build windows !cgo | ||
|
||
package parser | ||
|
||
import "github.com/wasilibs/go-pgquery/parser" | ||
|
||
type Error = parser.Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized these may have intentionally been only building and not testing before since there doesn't seem to be a reason for darwin to otherwise fail them. Let me know if I should revert these, but I thought it could be good to verify these work in CI
anuraaga@315cb5a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI I have also filed pganalyze/pg_query_go#103