mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
d9beb7690f
There are several places where rbuf_consume is called with @rbuf.size as its length arg; simplify that case by avoiding the slow String#slice! operation in favor of a lightweight replacement. The following script exhibits reduced memory usage and runtimes using the time(1) command: 2.9s => 2.6s 70MB => 12 MB --------- require 'net/http' require 'digest/md5' Thread.abort_on_exception = true s = TCPServer.new('127.0.0.1', 0) len = 1024 * 1024 * 1024 th = Thread.new do c = s.accept c.readpartial(16384) c.write("HTTP/1.0 200 OK\r\nContent-Length: #{len}\r\n\r\n") IO.copy_stream('/dev/zero', c, len) c.close end addr = s.addr Net::HTTP.start(addr[3], addr[1]) do |http| http.request_get('/') do |res| dig = Digest::MD5.new res.read_body { |buf| dig.update(buf) # String#clear is important to reduce malloc overhead, # but most Ruby programmers don't do this :< buf.clear } puts dig.hexdigest end end ---------- * lib/net/protocol (rbuf_consume): optimize for @rbuf.size == len [Feature #14268] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e |
||
---|---|---|
.. | ||
cgi | ||
drb | ||
forwardable | ||
irb | ||
matrix | ||
net | ||
optparse | ||
racc | ||
rdoc | ||
rexml | ||
rinda | ||
rss | ||
rubygems | ||
shell | ||
unicode_normalize | ||
uri | ||
webrick | ||
yaml | ||
.document | ||
abbrev.rb | ||
base64.rb | ||
benchmark.rb | ||
cgi.rb | ||
cmath.gemspec | ||
cmath.rb | ||
csv.gemspec | ||
csv.rb | ||
debug.rb | ||
delegate.rb | ||
drb.rb | ||
e2mmap.rb | ||
English.rb | ||
erb.rb | ||
fileutils.gemspec | ||
fileutils.rb | ||
find.rb | ||
forwardable.rb | ||
getoptlong.rb | ||
ipaddr.gemspec | ||
ipaddr.rb | ||
irb.rb | ||
logger.rb | ||
matrix.rb | ||
mkmf.rb | ||
monitor.rb | ||
mutex_m.rb | ||
observer.rb | ||
open-uri.rb | ||
open3.rb | ||
optionparser.rb | ||
optparse.rb | ||
ostruct.rb | ||
pp.rb | ||
prettyprint.rb | ||
prime.rb | ||
profile.rb | ||
profiler.rb | ||
pstore.rb | ||
rdoc.rb | ||
resolv-replace.rb | ||
resolv.rb | ||
rss.rb | ||
rubygems.rb | ||
scanf.gemspec | ||
scanf.rb | ||
securerandom.rb | ||
set.rb | ||
shell.rb | ||
shellwords.rb | ||
singleton.rb | ||
sync.rb | ||
tempfile.rb | ||
thwait.rb | ||
time.rb | ||
timeout.rb | ||
tmpdir.rb | ||
tracer.rb | ||
tsort.rb | ||
un.rb | ||
uri.rb | ||
weakref.rb | ||
webrick.rb | ||
yaml.rb |