Skip to content
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

feat: speed up ProtoMethods #108

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions features/fastreflection/proto_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,26 +288,34 @@ func (g *fastGenerator) genIsValid() {
}

func (g *fastGenerator) genProtoMethods() {
varName := g.typeName + "ProtoMethods"

g.P("// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations.")
g.P("// This method may return nil.")
g.P("//")
g.P("// The returned methods type is identical to")
g.P(`// "google.golang.org/protobuf/runtime/protoiface".Methods.`)
g.P("// Consult the protoiface package documentation for details.")
g.P("func (x *", g.typeName, ") ProtoMethods() *", protoifacePkg.Ident("Methods"), " {")
g.P("func (*", g.typeName, ") ProtoMethods() *", protoifacePkg.Ident("Methods"), " {")
g.P("return ", varName)
g.P("}")

g.P("var ", varName, " *", protoifacePkg.Ident("Methods"))

g.P("func init() {")
g.genSizeMethod()
g.genMarshalMethod()
g.genUnmarshalMethod()
g.genCheckInitializedMethod()

g.P("return &", protoifacePkg.Ident("Methods"), "{ ")
g.P(varName, " = &", protoifacePkg.Ident("Methods"), "{ ")
g.P("NoUnkeyedLiterals: struct{}{},")
g.P("Flags: ", protoifacePkg.Ident("SupportMarshalDeterministic"), "|", protoifacePkg.Ident("SupportUnmarshalDiscardUnknown"), ",")
g.P("Size: size,")
g.P("Marshal: marshal,")
g.P("Unmarshal: unmarshal,")
g.P("CheckInitialized: checkInitialized,")
g.P("Merge: nil,")
g.P("CheckInitialized: nil,")
g.P("}")
g.P("}")
}
7 changes: 7 additions & 0 deletions features/fastreflection/proto_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ func (g *fastGenerator) genUnmarshalMethod() {
g.P(`}`)
}

func (g *fastGenerator) genCheckInitializedMethod() {
// checkInitialized method.
g.P(`checkInitialized := func(input `, protoifacePkg.Ident("CheckInitializedInput"), `) (`, protoifacePkg.Ident("CheckInitializedOutput"), `, error) {`)
g.P(`return `, protoifacePkg.Ident("CheckInitializedOutput"), `{}, nil`)
g.P(`}`)
}

func (g *fastGenerator) decodeVarint(varName string, typName string) {
g.P(`for shift := uint(0); ; shift += 7 {`)
g.P(`if shift >= 64 {`)
Expand Down
47 changes: 37 additions & 10 deletions internal/testprotos/test3/test.pulsar.go

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

17 changes: 13 additions & 4 deletions internal/testprotos/test3/test_import.pulsar.go

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

62 changes: 49 additions & 13 deletions internal/testprotos/test3/test_nesting.pulsar.go

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

2 changes: 1 addition & 1 deletion rapidproto/testdata/seed1000.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"someBoolean":true, "INT32":112, "SINT32":20861, "UINT32":39, "INT64":"1916", "SING64":"-208", "UINT64":"95", "SFIXED32":-4267293, "FIXED32":56, "FLOAT":-0.061933517, "SFIXED64":"-128961679122", "FIXED64":"56609281", "DOUBLE":-4.2137932902833315e+218, "STRING":"a", "BYTES":"EQzPLBA1mwUBCQ==", "MAP":{"ž󠀶×a)?c":{"x":"Ʉ⃞➋-"}}, "ONEOFSTRING":"Aা𑅅҉^*[ॎ{؂Ⱥ\n@^<n", "type":"܏󠀫?“@\u0003~—!+‮#"}
{"someBoolean":true,"INT32":112,"SINT32":20861,"UINT32":39,"INT64":"1916","SING64":"-208","UINT64":"95","SFIXED32":-4267293,"FIXED32":56,"FLOAT":-0.061933517,"SFIXED64":"-128961679122","FIXED64":"56609281","DOUBLE":-4.2137932902833315e+218,"STRING":"a","BYTES":"EQzPLBA1mwUBCQ==","MAP":{"ž󠀶×a)?c":{"x":"Ʉ⃞➋-"}},"ONEOFSTRING":"Aা𑅅҉^*[ॎ{؂Ⱥ\n@^<n","type":"܏󠀫?“@\u0003~—!+‮#"}
2 changes: 1 addition & 1 deletion rapidproto/testdata/seed1001.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"someBoolean":true, "INT32":-3, "SINT32":-15161, "UINT32":22975, "INT64":"-10183", "SING64":"1", "UINT64":"118", "SFIXED32":283, "FIXED32":4294967295, "FLOAT":55.4375, "SFIXED64":"1", "FIXED64":"122", "DOUBLE":2.255889892109379e-30, "STRING":"ः\\\u0000", "BYTES":"Dqs=", "MESSAGE":{"x":"ꦽ:a Ⱥ"}, "MAP":{"\u0001/?-?aº":{"x":"٤"}, "!<ाAa\t":{"x":"₥"}, "$₈?a㱰ᛯ\u0000*ઃ":{"x":"􊬊݉?"}, "-\u0002𑴲፭":{"x":" ܏A!Ⱥ𐓃ꧦ\u001bƻি\țH꣕~ؔ𑱞"}}, "LIST":[{"x":"#aª*@𖽠"}, {"x":"A!\u001a??'[כ"}, {"x":"+𝍧~!\n~"}, {"x":"!&= ±bAᛮ؎°׆?Ֆ"}, {"x":"?*@ᾝ "}, {"x":"%𫑙%`푸𝕘𐡹҉܃"}, {"x":"7A𓐸₥?%"}, {"x":"\u0007a/ॉa"}, {"x":"$^A‪Ⱥ$"}, {"x":" B҈\u001b"}], "ONEOFSTRING":"&ϔ/`", "LISTENUM":["Two", "One", "Two", "Two", "Two"], "type":"҉𓐴A"}
{"someBoolean":true,"INT32":-3,"SINT32":-15161,"UINT32":22975,"INT64":"-10183","SING64":"1","UINT64":"118","SFIXED32":283,"FIXED32":4294967295,"FLOAT":55.4375,"SFIXED64":"1","FIXED64":"122","DOUBLE":2.255889892109379e-30,"STRING":"ः\\\u0000","BYTES":"Dqs=","MESSAGE":{"x":"ꦽ:a Ⱥ"},"MAP":{"\u0001/?-?aº":{"x":"٤"},"!<ाAa\t":{"x":"₥"},"$₈?a㱰ᛯ\u0000*ઃ":{"x":"􊬊݉?"},"-\u0002𑴲፭":{"x":" ܏A!Ⱥ𐓃ꧦ\u001bƻি\țH꣕~ؔ𑱞"}},"LIST":[{"x":"#aª*@𖽠"},{"x":"A!\u001a??'[כ"},{"x":"+𝍧~!\n~"},{"x":"!&= ±bAᛮ؎°׆?Ֆ"},{"x":"?*@ᾝ "},{"x":"%𫑙%`푸𝕘𐡹҉܃"},{"x":"7A𓐸₥?%"},{"x":"\u0007a/ॉa"},{"x":"$^A‪Ⱥ$"},{"x":" B҈\u001b"}],"ONEOFSTRING":"&ϔ/`","LISTENUM":["Two","One","Two","Two","Two"],"type":"҉𓐴A"}
2 changes: 1 addition & 1 deletion rapidproto/testdata/seed1002.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"enum":"Two", "INT32":-2718, "SINT32":-60035, "UINT32":2601799, "INT64":"-59", "SING64":"-2", "UINT64":"80", "FIXED32":1, "FLOAT":-0.08959961, "SFIXED64":"-2047", "FIXED64":"175", "DOUBLE":3.14684672949901e-85, "BYTES":"MB8=", "MESSAGE":{}, "ONEOFSTRING":"ⅾaՅ", "imported":{}}
{"enum":"Two","INT32":-2718,"SINT32":-60035,"UINT32":2601799,"INT64":"-59","SING64":"-2","UINT64":"80","FIXED32":1,"FLOAT":-0.08959961,"SFIXED64":"-2047","FIXED64":"175","DOUBLE":3.14684672949901e-85,"BYTES":"MB8=","MESSAGE":{},"ONEOFSTRING":"ⅾaՅ","imported":{}}
2 changes: 1 addition & 1 deletion rapidproto/testdata/seed1003.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"someBoolean":true, "INT32":-59, "SINT32":3, "UINT32":390, "INT64":"-2", "SING64":"-8", "SFIXED32":1171755373, "FIXED32":747, "FLOAT":-0.0033711107, "SFIXED64":"1", "FIXED64":"75", "DOUBLE":3.5, "LIST":[{"x":"{𑤳\""}, {}, {"x":"⃤¹⃢௹~‮±⪏"}, {"x":"*"}, {"x":"؜~"}, {"x":"~"}, {}, {"x":"AȺȺ᮵?֎៰"}], "ONEOFSTRING":"េ", "LISTENUM":["One", "Two", "Two"], "imported":{}, "type":"ʱ\u000b󠁇"}
{"someBoolean":true,"INT32":-59,"SINT32":3,"UINT32":390,"INT64":"-2","SING64":"-8","SFIXED32":1171755373,"FIXED32":747,"FLOAT":-0.0033711107,"SFIXED64":"1","FIXED64":"75","DOUBLE":3.5,"LIST":[{"x":"{𑤳\""},{},{"x":"⃤¹⃢௹~‮±⪏"},{"x":"*"},{"x":"؜~"},{"x":"~"},{},{"x":"AȺȺ᮵?֎៰"}],"ONEOFSTRING":"េ","LISTENUM":["One","Two","Two"],"imported":{},"type":"ʱ\u000b󠁇"}
2 changes: 1 addition & 1 deletion rapidproto/testdata/seed1004.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"INT32":-201, "SINT32":1, "UINT32":5, "INT64":"3", "SING64":"12", "UINT64":"2860198", "SFIXED32":3, "FIXED32":1597511853, "FLOAT":0.0002543144, "SFIXED64":"-33339063266", "FIXED64":"205355", "DOUBLE":-4.876529669536761e+251, "STRING":"ˌᾋ˧#₨뗭ॱ⨲0_-‮⓹+A~\u000b!ᤳ𐄘%w₥\u0000ᴭ", "BYTES":"BP+NAQ==", "ONEOFSTRING":"ả₿⸟؀1", "LISTENUM":["Two", "One", "One", "Two", "Two", "One", "One"], "imported":{}, "type":"@@\\"}
{"INT32":-201,"SINT32":1,"UINT32":5,"INT64":"3","SING64":"12","UINT64":"2860198","SFIXED32":3,"FIXED32":1597511853,"FLOAT":0.0002543144,"SFIXED64":"-33339063266","FIXED64":"205355","DOUBLE":-4.876529669536761e+251,"STRING":"ˌᾋ˧#₨뗭ॱ⨲0_-‮⓹+A~\u000b!ᤳ𐄘%w₥\u0000ᴭ","BYTES":"BP+NAQ==","ONEOFSTRING":"ả₿⸟؀1","LISTENUM":["Two","One","One","Two","Two","One","One"],"imported":{},"type":"@@\\"}
Loading