normal e1dd1fc35c open-uri: clear string after buffering
Since r58846 (in Ruby 2.5), it is safe to clear the string
yielded to Net::HTTPResponse#read_body methods.  This
reduces malloc garbage (anonymous RSS) using the Linux-only
script below:

before:  user     system      total        real
      0.030000   0.250000   0.280000 (  0.280511)
    RssAnon:	   60240 kB

 after:  user     system      total        real
      0.050000   0.223333   0.273333 (  0.273118)
    RssAnon:	    6676 kB

------
  # warning this script requires 1G free space for buffering
require 'open-uri'
require 'socket'
require 'benchmark'

s = TCPServer.new('127.0.0.1', 0)
len = 1024 * 1024 * 1024
buf = ((0..255).map(&:chr).join * 128)
nr = len / buf.size
pid = fork do
  c = s.accept
  c.readpartial(16384).clear
  c.write("HTTP/1.1 200 OK\r\n" \
	  "Content-Length: #{len}\r\n" \
          "Content-Type: application/octet-stream\r\n" \
          "\r\n")
  buf.freeze # speeds up IO#write slightly
  nr.times { c.write(buf) }
  c.close
end

addr = s.addr
open("http://#{addr[3]}:#{addr[1]}/", "rb") do |fp|
  bm = Benchmark.measure do
    while fp.read(16384, buf)
    end
  end
  puts bm
end
puts File.readlines("/proc/#$$/status").grep(/RssAnon/)[0]
Process.waitpid2(pid)
------

* lib/open-uri.rb: clear string yielded by Net::HTTPResponse#read_body
  [ruby-core:84662] [Feature #14320]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61664 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-08 01:11:33 +00:00
..
2017-12-30 12:10:43 +00:00
2016-11-20 02:12:48 +00:00
2016-10-14 13:26:13 +00:00
2017-10-22 11:27:06 +00:00
2017-12-31 00:06:34 +00:00
2017-10-08 07:00:01 +00:00
2017-12-25 05:54:27 +00:00
2017-10-08 07:00:01 +00:00
2017-12-14 06:30:22 +00:00
2017-12-24 08:38:43 +00:00
2017-09-12 08:38:06 +00:00
2017-12-22 08:00:10 +00:00
2017-12-22 08:00:10 +00:00
2017-09-02 02:05:34 +00:00
2017-10-21 13:34:19 +00:00
2017-12-25 07:55:25 +00:00
2017-10-08 07:00:01 +00:00
2017-10-08 07:00:01 +00:00
2017-12-23 23:33:09 +00:00
2017-12-20 04:25:01 +00:00
2017-12-22 23:08:05 +00:00
2018-01-07 17:49:46 +00:00
2017-11-22 21:13:51 +00:00
2016-11-05 23:58:02 +00:00
2017-10-08 07:00:01 +00:00
2017-10-08 07:00:01 +00:00