[#99426] [Ruby master Bug#17098] Float#negative? reports negative zero as not negative — chris@...

Issue #17098 has been reported by chrisseaton (Chris Seaton).

12 messages 2020/08/01

[#99449] [Ruby master Bug#17100] Ractor: a proposal for new concurrent abstraction without thread-safety issues — ko1@...

Issue #17100 has been reported by ko1 (Koichi Sasada).

41 messages 2020/08/03

[#99474] [Ruby master Feature#17103] Add a :since option to ObjectSpace.dump_all — jean.boussier@...

Issue #17103 has been reported by byroot (Jean Boussier).

9 messages 2020/08/04

[#99485] [Ruby master Misc#17104] Why are interpolated string literals frozen? — bughitgithub@...

Issue #17104 has been reported by bughit (bug hit).

23 messages 2020/08/05

[#99499] [Ruby master Bug#17105] A single `return` can return to two different places in a proc inside a lambda inside a method — eregontp@...

Issue #17105 has been reported by Eregon (Benoit Daloze).

10 messages 2020/08/06

[#99582] [Ruby master Feature#17122] Add category to Warning#warn — eileencodes@...

Issue #17122 has been reported by eileencodes (Eileen Uchitelle).

20 messages 2020/08/13

[#99700] [Ruby master Bug#17129] bundle install `eventmachine` and `sassc` fails since 914b2208ab3eddec478cdc3e079e6c30d0f0892c — yasuo.honda@...

SXNzdWUgIzE3MTI5IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IHlhaG9uZGEgKFlhc3VvIEhvbmRhKS4N

9 messages 2020/08/26

[ruby-core:99530] [Ruby master Feature#17111] Improve performance of Net::HTTPHeader#set_form by 40%

From: tonytonyjan@...
Date: 2020-08-10 04:09:30 UTC
List: ruby-core #99530
Issue #17111 has been reported by tonytonyjan (Wei-Hang Jian).

----------------------------------------
Feature #17111: Improve performance of Net::HTTPHeader#set_form by 40%
https://bugs.ruby-lang.org/issues/17111

* Author: tonytonyjan (Wei-Hang Jian)
* Status: Open
* Priority: Normal
----------------------------------------
## diff

```diff
diff --git a/lib/net/http/header.rb b/lib/net/http/header.rb
index a8901e7..3f1a008 100644
--- a/lib/net/http/header.rb
+++ b/lib/net/http/header.rb
@@ -475,9 +475,8 @@ def set_form(params, enctype='application/x-www-form-urlencoded', formopt={})
     @body = nil
     @body_stream = nil
     @form_option = formopt
-    case enctype
-    when /\Aapplication\/x-www-form-urlencoded\z/i,
-      /\Amultipart\/form-data\z/i
+    case enctype.downcase
+    when 'application/x-www-form-urlencoded', 'multipart/form-data'
       self.content_type = enctype
     else
       raise ArgumentError, "invalid enctype: #{enctype}"
```

## benchmark

```ruby
require 'benchmark'
require 'net/http'

module Net::HTTPHeader
  def set_form2(params, enctype = 'application/x-www-form-urlencoded', formopt = {})
    @body_data = params
    @body = nil
    @body_stream = nil
    @form_option = formopt
    case enctype.downcase
    when 'application/x-www-form-urlencoded', 'multipart/form-data'
      self.content_type = enctype
    else
      raise ArgumentError, "invalid enctype: #{enctype}"
    end
  end
end

n = 500_000
request = Net::HTTP::Post.new('/')
Benchmark.bm do |x|
  GC.disable
  x.report { n.times { request.set_form [] } }
  x.report { n.times { request.set_form2 [] } }
end
```

```
       user     system      total        real
   0.777054   0.101768   0.878822 (  0.880472)
   0.539860   0.088957   0.628817 (  0.630178)
```

I don't see any test for `#set_form` in `test/net/http/test_httpheader.rb`, let me know if I need to add more tests, thanks!

---Files--------------------------------
patch-1.diff (621 Bytes)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next