ruby/lib
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
..
cgi Use printf instead of puts and sprintf 2017-12-12 15:01:04 +00:00
drb drb: use \A and \z 2017-12-30 12:10:43 +00:00
forwardable forwardable/impl.rb 2016-11-20 02:12:48 +00:00
irb proc.c (bind_location): Add Binding#source_location 2017-12-26 08:38:35 +00:00
matrix get rid of ambiguous parentheses warnings 2016-11-29 16:06:54 +00:00
net net/protocol: read directly into rbuf if it's empty 2018-01-08 00:34:47 +00:00
optparse optparse/kwargs.rb 2016-10-14 13:26:13 +00:00
racc Fixed misspelling words. 2017-10-22 11:27:06 +00:00
rdoc fix reset order. 2017-12-31 00:06:34 +00:00
rexml Add uplevel keyword to Kernel#warn and use it 2017-12-12 11:56:25 +00:00
rinda Remove unnecessary `require 'thread'` 2017-10-08 07:00:01 +00:00
rss Add uplevel keyword to Kernel#warn and use it 2017-12-12 11:56:25 +00:00
rubygems fix leaked fds 2017-12-25 05:54:27 +00:00
shell Remove unnecessary `require 'thread'` 2017-10-08 07:00:01 +00:00
unicode_normalize update Ruby to Unicode 10.0.0 2017-09-06 07:56:41 +00:00
uri Use string instead of regexp 2017-12-14 06:30:22 +00:00
webrick webrick 1.4.2 2017-12-24 08:38:43 +00:00
yaml * lib/yaml/store.rb (YAML::Store#dump): use table argument instead of @table directly. 2016-09-29 14:40:34 +00:00
.document Ignore gemspec under the lib directory for documentation. 2017-12-12 08:34:13 +00:00
English.rb `$IGNORECASE` is no longer effective. [ci skip] 2017-08-25 15:47:04 +00:00
abbrev.rb lib/abbrev.rb: Specify frozen_string_literal: true. 2017-02-09 16:12:00 +00:00
base64.rb Use `unpack1` instead of `unpack` and `first` 2017-02-10 00:58:47 +00:00
benchmark.rb lib/benchmark.rb: Specify frozen_string_literal: true. 2017-01-03 02:00:01 +00:00
cgi.rb {lib,test}/cgi: Specify frozen_string_literal: true. 2017-02-18 05:52:16 +00:00
cmath.gemspec Bump version to cmath-1.0.0 as default gems. 2017-12-11 03:27:47 +00:00
cmath.rb Add uplevel keyword to Kernel#warn and use it 2017-12-12 11:56:25 +00:00
csv.gemspec Bump version to csv-1.0.0 as default gems. 2017-12-13 05:24:01 +00:00
csv.rb Merge csv-0.1.0 from upstream. 2017-09-12 08:38:06 +00:00
debug.rb lib/debug.rb: Specify frozen_string_literal: true. 2017-01-05 01:00:01 +00:00
delegate.rb Add uplevel keyword to Kernel#warn and use it 2017-12-12 11:56:25 +00:00
drb.rb Add frozen_string_literal: false for all files 2015-12-16 05:07:31 +00:00
e2mmap.rb lib/e2mmap.rb: Specify frozen_string_literal: true. 2017-03-01 11:37:30 +00:00
erb.rb `$SAFE` as a process global state. [Feature #14250] 2017-12-28 20:09:24 +00:00
fileutils.gemspec Bump up fileutils-1.0.2 2017-12-22 08:00:10 +00:00
fileutils.rb Bump up fileutils-1.0.2 2017-12-22 08:00:10 +00:00
find.rb Find.find -> Use Dir.children instead of Dir.entries 2017-09-15 17:00:49 +00:00
forwardable.rb Add uplevel keyword to Kernel#warn and use it 2017-12-12 11:56:25 +00:00
getoptlong.rb getoptlong.rb: multiline regexps 2017-09-02 02:05:34 +00:00
ipaddr.gemspec Import ipaddr 1.2.0 2017-10-21 13:34:19 +00:00
ipaddr.rb Add uplevel keyword to Kernel#warn and use it 2017-12-12 11:56:25 +00:00
irb.rb irb.rb: fix highlight 2017-12-25 07:55:25 +00:00
logger.rb * lib/logger.rb (Logger::LogDevice#open_logfile, #create_logfile): 2017-12-21 05:07:43 +00:00
matrix.rb Add uplevel keyword to Kernel#warn and use it 2017-12-12 11:56:25 +00:00
mkmf.rb int (*)(void) is incompatible with void* 2018-01-02 06:41:42 +00:00
monitor.rb Remove unnecessary `require 'thread'` 2017-10-08 07:00:01 +00:00
mutex_m.rb Remove unnecessary `require 'thread'` 2017-10-08 07:00:01 +00:00
observer.rb lib/observer.rb: Specify frozen_string_literal: true. 2017-01-13 12:08:29 +00:00
open-uri.rb open-uri: clear string after buffering 2018-01-08 01:11:33 +00:00
open3.rb lib/open3.rb: accept IO-like object for :stdin_data argument. 2017-10-21 07:00:58 +00:00
optionparser.rb Add frozen_string_literal: false for all files 2015-12-16 05:07:31 +00:00
optparse.rb optparse.rb: case-sensitive candidate 2017-07-24 01:56:04 +00:00
ostruct.rb Add uplevel keyword to Kernel#warn and use it 2017-12-12 11:56:25 +00:00
pp.rb Requiring pp is not required now [ci skip] 2017-12-18 01:51:53 +00:00
prettyprint.rb * lib/open-uri.rb: Remove indicator for "frozen_string_literal: true". 2015-11-10 11:48:14 +00:00
prime.rb prime.rb: remove alias after timeout test 2017-05-20 10:21:44 +00:00
profile.rb lib/profile.rb: Specify frozen_string_literal: true. 2017-01-15 02:56:04 +00:00
profiler.rb lib/profiler.rb: Specify frozen_string_literal: true. 2017-01-18 12:35:10 +00:00
pstore.rb lib/pstore.rb: Specify frozen_string_literal: true. 2017-01-17 12:47:38 +00:00
rdoc.rb Merge rdoc-6.0.1. 2017-12-23 23:33:09 +00:00
resolv-replace.rb * lib/resolv-replace.rb: Specify frozen_string_literal: true. 2015-11-14 08:25:30 +00:00
resolv.rb Fixed command Injection 2017-12-20 04:25:01 +00:00
rss.rb Add frozen_string_literal: false for all files 2015-12-16 05:07:31 +00:00
rubygems.rb Postponing the Bundler merge. 2017-12-22 23:08:05 +00:00
scanf.gemspec Bump version to scanf-1.0.0 as default gems. 2017-12-11 08:18:01 +00:00
scanf.rb lib/scanf.rb: [DOC] fix typos 2018-01-07 17:49:46 +00:00
securerandom.rb securerandom.rb: fix an example of choose [ci skip] 2017-10-25 07:28:22 +00:00
set.rb lib/set.rb: [DOC] remove empty comments 2017-11-22 21:13:51 +00:00
shell.rb shell.rb: suppress warnings 2016-11-05 23:58:02 +00:00
shellwords.rb Fix the handling of the backslash in double quotes 2016-11-05 04:58:48 +00:00
singleton.rb Remove unnecessary `require 'thread'` 2017-10-08 07:00:01 +00:00
sync.rb * lib/sync.rb: Fix NameError when error. 2016-09-18 10:24:48 +00:00
tempfile.rb Add uplevel keyword to Kernel#warn and use it 2017-12-12 11:56:25 +00:00
thwait.rb Remove unnecessary `require 'thread'` 2017-10-08 07:00:01 +00:00
time.rb Make Time.parse respect timezone offset seconds 2017-10-20 01:03:18 +00:00
timeout.rb Add uplevel keyword to Kernel#warn and use it 2017-12-12 11:56:25 +00:00
tmpdir.rb tmpdir.rb: merged make_tmpname to create 2017-11-15 08:02:09 +00:00
tracer.rb Remove unnecessary `require 'thread'` 2017-10-08 07:00:01 +00:00
tsort.rb * lib/tsort.rb: Specify frozen_string_literal: true. 2015-11-14 08:46:11 +00:00
un.rb un.rb: use OpenSSL::PKey.read instead of OpenSSL::PKey::RSA.new 2017-07-05 09:05:53 +00:00
uri.rb Add frozen_string_literal: false for all files 2015-12-16 05:07:31 +00:00
weakref.rb lib/weakref: Remove incorrect example [DOC] [Bug #14031] 2017-10-24 18:08:00 +00:00
webrick.rb [DOC] Fix typos 2015-12-23 03:43:23 +00:00
yaml.rb Add uplevel keyword to Kernel#warn and use it 2017-12-12 11:56:25 +00:00