json-iterator / java

jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go
http://jsoniter.com/
MIT License
1.5k stars 519 forks source link

Fixed leaky buffer when streaming. #243

Closed svobol13 closed 2 years ago

svobol13 commented 5 years ago

Reworked a way how internal buffer size increases when streaming. The new way changes both when and how it increases size.

When: Whenever current buffer size is fully utilized AND autoresizing is enabled. How: It increases buffer size with configured absolute number of bytes instead of doubling the capacity.

New API: Added new factory method parse(InputStream in, int bufSize, int autoExpandBufferStep) that creates Iterator with posibility to control how autoresizing works. Set 0 to disable, set 5 to increase buffer size of 5 bytes everytime we hit end.

Backward compatibility: Factory parse(InputStream in, int bufSize) was changed with respect to previous setting. First increase of buffer size is exactly same as it was in pass though any subsequent increase is same size as first one in contrast to previous behaviour (it was growing exponentially).

codecov-io commented 5 years ago

Codecov Report

Merging #243 into master will increase coverage by 0.04%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #243      +/-   ##
=========================================
+ Coverage   68.46%   68.5%   +0.04%     
=========================================
  Files         107     107              
  Lines        7335    7338       +3     
  Branches     1388    1389       +1     
=========================================
+ Hits         5022    5027       +5     
+ Misses       1867    1866       -1     
+ Partials      446     445       -1
Impacted Files Coverage Δ
src/main/java/com/jsoniter/IterImpl.java 66.11% <ø> (ø) :arrow_up:
...c/main/java/com/jsoniter/IterImplForStreaming.java 70.73% <100%> (+0.46%) :arrow_up:
src/main/java/com/jsoniter/JsonIterator.java 65.54% <100%> (+0.52%) :arrow_up:

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 e48a7a1...2a575f8. Read the comment docs.