[ruby-cvs:67767] normal:r60586 (trunk): webrick/httpresponse: minor cleanups to reduce memory use

normal at ruby-lang.org normal at ruby-lang.org
Tue Oct 31 10:37:38 JST 2017

normal	2017-10-31 10:37:37 +0900 (Tue, 31 Oct 2017)

  New Revision: 60586


    webrick/httpresponse: minor cleanups to reduce memory use
    I never knew "format" was a global method alias for "sprintf";
    so it was confusing to me.  Normally, one would use "sprintf"
    since it's also available in many other languages, but
    Integer#to_s avoids parsing a format string so it's less
    Furthermore, favor string interpolation over String#<< since it
    is easier for the VM to optimize memory allocation (as in r60320).
    Interpolation also reduces method calls and memory overhead
    for inline method cache.
    Finally, ensure we clear all short-lived buffers for body
    responses.  A similar change was made and measured for Net::*
    in r58840 showing a large memory reduction on some workloads.
    * webrick/httpresponse.rb (send_body_io): favor String#to_s,
      reduce method calls for String#<<,
      clear `buf' when done,
      avoid extra String#bytesize calls
    * (send_body_string): ditto

  Modified files:

More information about the ruby-cvs mailing list