[ 
https://issues.apache.org/jira/browse/BEAM-13082?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17431413#comment-17431413
 ] 

Robert Burke commented on BEAM-13082:
-------------------------------------

Running the benchmark before and after 5 times, we can see the improvements.

{{benchstat old.txt new.txt                                           
name                old time/op    new time/op    delta
DataWriter/4B-8       11.1ns ±25%     5.5ns ±10%  -50.16%  (p=0.008 n=5+5)
DataWriter/16B-8      22.2ns ±15%     6.0ns ± 4%  -72.87%  (p=0.008 n=5+5)
DataWriter/1KB-8       949ns ±10%      51ns ±22%  -94.64%  (p=0.008 n=5+5)
DataWriter/4KB-8      3.47µs ± 3%    0.16µs ±30%  -95.47%  (p=0.008 n=5+5)
DataWriter/100KB-8    72.6µs ± 7%     4.3µs ±12%  -94.01%  (p=0.008 n=5+5)
DataWriter/1MB-8       313µs ± 5%      74µs ±21%  -76.34%  (p=0.008 n=5+5)
DataWriter/10MB-8     1.28ms ± 3%    1.15ms ±10%     ~     (p=0.056 n=5+5)
DataWriter/100MB-8    15.6ms ±18%    12.4ms ± 2%  -20.91%  (p=0.008 n=5+5)
DataWriter/256MB-8    55.4ms ±87%    31.8ms ± 2%  -42.48%  (p=0.008 n=5+5)

name                old alloc/op   new alloc/op   delta
DataWriter/4B-8        23.0B ± 0%      0.0B          ~     (p=0.079 n=4+5)
DataWriter/16B-8       91.0B ± 0%      0.0B          ~     (p=0.079 n=4+5)
DataWriter/1KB-8      5.89kB ± 0%   0.00kB ±100%  -99.99%  (p=0.008 n=5+5)
DataWriter/4KB-8      23.6kB ± 0%     0.0kB ±25%  -99.99%  (p=0.008 n=5+5)
DataWriter/100KB-8     492kB ± 0%       0kB ±14%  -99.99%  (p=0.008 n=5+5)
DataWriter/1MB-8      2.27MB ± 0%    0.00MB ±22%  -99.98%  (p=0.008 n=5+5)
DataWriter/10MB-8     10.5MB ± 0%     0.0MB ±13%  -99.90%  (p=0.008 n=5+5)
DataWriter/100MB-8     105MB ± 0%       1MB ± 7%  -98.93%  (p=0.008 n=5+5)
DataWriter/256MB-8     268MB ± 0%       8MB ± 6%  -97.14%  (p=0.008 n=5+5)

name                old allocs/op  new allocs/op  delta
DataWriter/4B-8         0.00           0.00          ~     (all equal)
DataWriter/16B-8        0.00           0.00          ~     (all equal)
DataWriter/1KB-8        0.00           0.00          ~     (all equal)
DataWriter/4KB-8        0.00           0.00          ~     (all equal)
DataWriter/100KB-8      0.00           0.00          ~     (all equal)
DataWriter/1MB-8        2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.008 n=5+5)
DataWriter/10MB-8       6.00 ± 0%      5.00 ± 0%  -16.67%  (p=0.008 n=5+5)
DataWriter/100MB-8      6.00 ± 0%      5.00 ± 0%  -16.67%  (p=0.008 n=5+5)
DataWriter/256MB-8      6.00 ± 0%      5.00 ± 0%  -16.67%  (p=0.008 n=5+5)}}


> [Go SDK] Reduce churn in dataWriter by retaining byte slice.
> ------------------------------------------------------------
>
>                 Key: BEAM-13082
>                 URL: https://issues.apache.org/jira/browse/BEAM-13082
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-go
>            Reporter: Robert Burke
>            Assignee: Robert Burke
>            Priority: P2
>
> It's been noted that we can reduce allocations and GC overhead produced by 
> the dataWriter if we change the `w.buf = nil` to `w.buf = w.buf[:0]`. We 
> should still nil out the buffer after the final flush in Close() however, to 
> avoid retaining larger byte buffers after bundle termination.
> A dataWriter is created per bundle, and is only used and is safe to use by 
> that bundle 's processing thread. Further, GRPC's Send call doesn't maintain 
> ownership of the Proto message data after Send returns, allowing this re-use.
> A later optimization could use a sync.Pool to maintain a "freelist" of 
> buffers to further reduce per bundle allocations but this would likely only 
> be noticeable in streaming contexts. Such a free list should have a cap of 
> keeping buffers under some threshold (say slices under 64MB in cap) to avoid 
> retaining overly large buffers that aren't in active use. This idea though is 
> out of scope for a first pass.



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

Reply via email to