thriftrw / thriftrw-go

A Thrift encoding code generator and library for Go
MIT License
101 stars 53 forks source link

Add pooling to the stream reader so that resources can be returned to the system #510

Closed dianale31 closed 3 years ago

dianale31 commented 3 years ago

Adds a sync.Pool to the StreamReader implementation to allow callers to borrow a StreamReader and return it after finishing work.

The binary.Reader implementation continues to instantiate the StreamReader because the binary.Reader.ReadValue method cannot return a StreamReader to the system since methods on container types like ForEach need access to the StreamReader to iterate through items. newStreamReader is unexported to make it only usable by internal ThriftRW callers. External callers of the StreamReader should use protocol.BinaryStreamer.Reader(io.Reader) and the StreamReader.Close() method.

codecov[bot] commented 3 years ago

Codecov Report

Merging #510 (a9d635a) into streamdev (c9605ac) will increase coverage by 0.00%. The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           streamdev     #510   +/-   ##
==========================================
  Coverage      68.80%   68.81%           
==========================================
  Files            129      129           
  Lines          22738    22747    +9     
==========================================
+ Hits           15646    15653    +7     
- Misses          4068     4070    +2     
  Partials        3024     3024           
Impacted Files Coverage Δ
protocol/binary/stream_reader.go 98.95% <80.00%> (-1.05%) :arrow_down:
protocol/binary.go 87.69% <100.00%> (-0.19%) :arrow_down:
protocol/binary/reader.go 83.48% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c9605ac...a9d635a. Read the comment docs.

abhinav commented 3 years ago

Superseded by #514