BytedanceRPC created THRIFT-5337:
------------------------------------

             Summary: Go set fields write improvement
                 Key: THRIFT-5337
                 URL: https://issues.apache.org/jira/browse/THRIFT-5337
             Project: Thrift
          Issue Type: Improvement
          Components: Go - Compiler
            Reporter: BytedanceRPC


There is a duplicate elements check for set in `writeFields*` function,  and it 
compares elements using `reflect.DeepEqual` which is expensive.

It's much faster that generates a "DeepEqual" function for set elements and 
apply it in duplicate elements check, especially for nested struct element.

For example, a thrift file like this:

 
{code:java}
namespace go bytedance.thrift.example

struct Simple {
 1: set<double> DoubleSet
}

struct Base {
 1: set<i64> I64Set
}

struct WrappedBase {
 1: set<Base> BaseSet
}

struct Nested {
 1: set<WrappedBase> WrappedBaseSet
}
{code}
 

Go generator would generate `Equals` method for structs defined in thrift file.

generated file diff: 
https://gist.github.com/BytedanceRPC/1aa34b65cf4c9efabed0d0a115262d85

 

 

Benchmark writeField1 for Simple and Nested:
{code:java}
name                 old time/op    new time/op    delta
SimpleWriteField1-8     576ns ± 3%     435ns ± 3%  -24.56%  (p=0.000 n=10+10)
NestedWriteField1-8     257µs ± 3%       3µs ± 5%  -98.71%  (p=0.000 
n=10+10)name                 old alloc/op   new alloc/op   delta
SimpleWriteField1-8      160B ± 0%      153B ± 0%   -4.58%  (p=0.000 n=8+9)
NestedWriteField1-8    45.5kB ± 0%     0.4kB ± 1%  -99.23%  (p=0.000 
n=9+10)name                 old allocs/op  new allocs/op  delta
SimpleWriteField1-8      6.00 ± 0%      4.00 ± 0%  -33.33%  (p=0.000 n=10+10)
NestedWriteField1-8     2.22k ± 0%     0.01k ± 0%  -99.68%  (p=0.000 n=10+10)
{code}
 

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to