Skip to content

Commit

Permalink
Use concrete struct type for FieldSpecs
Browse files Browse the repository at this point in the history
Summary:
Improves memory situation and (possibly) performance:
```
# Before
BenchmarkStructRead-166             1000           2919910 ns/op
BenchmarkStructWrite-166            1000           1915671 ns/op

# After
BenchmarkStructRead-166             1000           2877417 ns/op
BenchmarkStructWrite-166            1000           1871540 ns/op
```

Reviewed By: leoleovich

Differential Revision: D65249408

fbshipit-source-id: 1733faa22b004ced88eb5750d0dcd5e45f3bafb3
  • Loading branch information
echistyakov authored and facebook-github-bot committed Oct 31, 2024
1 parent b5b8c31 commit 78e5b27
Show file tree
Hide file tree
Showing 81 changed files with 895 additions and 895 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Name: "{{struct:name}}",
IsUnion: {{#struct:union?}}true{{/struct:union?}}{{^struct:union?}}false{{/struct:union?}},
IsException: {{#struct:exception?}}true{{/struct:exception?}}{{^struct:exception?}}false{{/struct:exception?}},
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{{#struct:fields_sorted}}
{{> spec/codec_field_spec}}
{{/struct:fields_sorted}}
Expand Down
80 changes: 40 additions & 40 deletions thrift/compiler/test/fixtures/adapter/out/go/gen-go/module/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "MyAnnotation",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.STRING),
Expand All @@ -740,7 +740,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "Foo",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.I32),
Expand Down Expand Up @@ -848,7 +848,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "Baz",
IsUnion: true,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.I32),
Expand Down Expand Up @@ -902,7 +902,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "Bar",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.STRUCT),
Expand Down Expand Up @@ -974,7 +974,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "DirectlyAdapted",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.I32),
Expand All @@ -992,7 +992,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "IndependentDirectlyAdapted",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.I32),
Expand All @@ -1010,7 +1010,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "StructWithFieldAdapter",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.I32),
Expand Down Expand Up @@ -1055,7 +1055,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "TerseAdaptedFields",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.I32),
Expand Down Expand Up @@ -1091,7 +1091,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "B",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.STRUCT),
Expand All @@ -1109,7 +1109,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "A",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
},
FieldSpecIDToIndex: map[int16]int{
},
Expand All @@ -1118,7 +1118,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "Config",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.STRING),
Expand All @@ -1136,7 +1136,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "MyStruct",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.I32),
Expand All @@ -1163,7 +1163,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "AdaptTestStruct",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.I64),
Expand Down Expand Up @@ -1262,7 +1262,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "AdaptTemplatedTestStruct",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.BOOL),
Expand Down Expand Up @@ -1469,7 +1469,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "AdaptTemplatedNestedTestStruct",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.STRUCT),
Expand All @@ -1487,7 +1487,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "AdaptTestUnion",
IsUnion: true,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.I64),
Expand All @@ -1514,7 +1514,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "AdaptedStruct",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.I64),
Expand All @@ -1532,7 +1532,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "DirectlyAdaptedStruct",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.I64),
Expand All @@ -1550,7 +1550,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "StructFieldAdaptedStruct",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.STRUCT),
Expand Down Expand Up @@ -1595,7 +1595,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "CircularAdaptee",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.STRUCT),
Expand All @@ -1613,7 +1613,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "CircularStruct",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.STRUCT),
Expand All @@ -1631,7 +1631,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "ReorderedStruct",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.STRUCT),
Expand All @@ -1649,7 +1649,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "DeclaredAfterStruct",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
},
FieldSpecIDToIndex: map[int16]int{
},
Expand All @@ -1658,7 +1658,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "RenamedStruct",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.I64),
Expand All @@ -1676,7 +1676,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "SameNamespaceStruct",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.I64),
Expand All @@ -1694,7 +1694,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "HeapAllocated",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
},
FieldSpecIDToIndex: map[int16]int{
},
Expand All @@ -1703,7 +1703,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "MoveOnly",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.STRUCT),
Expand All @@ -1721,7 +1721,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "AlsoMoveOnly",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.I64),
Expand All @@ -1739,7 +1739,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "ApplyAdapter",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
},
FieldSpecIDToIndex: map[int16]int{
},
Expand All @@ -1748,7 +1748,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "TransitiveAdapted",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
},
FieldSpecIDToIndex: map[int16]int{
},
Expand All @@ -1757,7 +1757,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "CountingStruct",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.I64),
Expand Down Expand Up @@ -1793,7 +1793,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "Person",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.STRING),
Expand All @@ -1811,7 +1811,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "Person2",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.STRING),
Expand All @@ -1829,7 +1829,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "RenamedStructWithStructAdapterAndFieldAdapter",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.I32),
Expand All @@ -1847,7 +1847,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "reqServiceFunc",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.STRING),
Expand Down Expand Up @@ -1883,7 +1883,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "respServiceFunc",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 0,
WireType: thrift.Type(thrift.I32),
Expand All @@ -1901,7 +1901,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "reqAdapterServiceCount",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
},
FieldSpecIDToIndex: map[int16]int{
},
Expand All @@ -1910,7 +1910,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "respAdapterServiceCount",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 0,
WireType: thrift.Type(thrift.STRUCT),
Expand All @@ -1928,7 +1928,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "reqAdapterServiceAdaptedTypes",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 1,
WireType: thrift.Type(thrift.STRUCT),
Expand All @@ -1946,7 +1946,7 @@ var premadeStructSpecsInitOnce = sync.OnceFunc(func() {
Name: "respAdapterServiceAdaptedTypes",
IsUnion: false,
IsException: false,
FieldSpecs: []*thrift.FieldSpec{
FieldSpecs: []thrift.FieldSpec{
{
ID: 0,
WireType: thrift.Type(thrift.STRUCT),
Expand Down
Loading

0 comments on commit 78e5b27

Please sign in to comment.