lo icon indicating copy to clipboard operation
lo copied to clipboard

feat(emptyabletoptr): Optimize the performance of EmptyableToPtr()

Open nextzhou opened this issue 2 years ago • 0 comments

Replace reflect operations with unsafe memory operations and add corresponding benchmark. Here are the comparison results of the benchmark(time consumption reduced by 97%):

name                                 old time/op    new time/op    delta
EmptyableToPtr/lo.EmptyableToPtr-16    54.5ns ± 1%     1.5ns ± 0%   -97.16%  (p=0.016 n=5+4)
EmptyableToPtr/if-16                   0.39ns ± 0%    0.39ns ± 0%      ~     (p=0.254 n=5+5)

name                                 old alloc/op   new alloc/op   delta
EmptyableToPtr/lo.EmptyableToPtr-16     16.0B ± 0%      0.0B       -100.00%  (p=0.008 n=5+5)

name                                 old allocs/op  new allocs/op  delta
EmptyableToPtr/lo.EmptyableToPtr-16      1.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)

nextzhou avatar May 26 '23 07:05 nextzhou