[rack] Parse query string with URI.decode_www_form - #1433
Merged
Conversation
URI.decode_www_form performs better than Rack::Utils which also supports
parsing nested params:
```ruby
require 'benchmark/ips'
require 'cgi'
require 'uri'
require 'rack'
Benchmark.ips do |x|
x.config(warmup: 2, time: 5)
query_string = "?a=14&b=54"
x.report("CGI") do
::CGI.parse(query_string)
end
x.report("URI.decode_www_form") do
URI.decode_www_form(query_string).to_h
end
x.report("Rack::Utils.parse_query") do
::Rack::Utils.parse_query(query_string)
end
x.compare!
end
```
ruby 3.4.9 (2026-03-11 revision 76cca827ab) +PRISM [arm64-darwin24]
Warming up --------------------------------------
CGI 60.058k i/100ms
URI.decode_www_form 63.568k i/100ms
Rack::Utils.parse_query 40.922k i/100ms
Calculating -------------------------------------
CGI 632.535k (± 2.4%) i/s (1.58 μs/i) - 3.183M in 5.032252s
URI.decode_www_form 667.942k (± 2.0%) i/s (1.50 μs/i) - 3.369M in 5.044006s
Rack::Utils.parse_query 417.398k (± 2.5%) i/s (2.40 μs/i) - 2.087M in 5.000076s
Comparison:
URI.decode_www_form: 667942.1 i/s
CGI: 632534.7 i/s - 1.06x slower
Rack::Utils.parse_query: 417398.1 i/s - 1.60x slower
Contributor
Author
|
/benchmark-multiple --save |
Contributor
|
👋 Benchmark request received. A collaborator will review and approve the run. |
Contributor
Benchmark ResultsFrameworks: 2 | Test: ✅
|
| Test | Conn | RPS | Rate | CPU/req | p99 | p99.9 | CPU | Mem | Δ RPS | Δ Mem |
|---|---|---|---|---|---|---|---|---|---|---|
| baseline | 4096 | 541,466 | — | — | — | — | 6562.8% | 1.1GiB | +3.4% | -15.4% |
| pipelined | 4096 | 801,850 | — | — | — | — | 6666.4% | 1.0GiB | +0.7% | ~0% |
| limited-conn | 4096 | 503,900 | — | — | — | — | 6255.5% | 894MiB | +4.6% | -32.8% |
| latency-1m | 1024 | 569,602 | 0.5696 |
111.96us | 10940416.0us | 12251136.0us | 6544.5% | 831MiB | +3.7% | -26.2% |
| latency-10k | 1024 | 9,982 | 0.9982 | 122.50us | 524.0us | 12580.0us | 118.8% | 765MiB | ~0% | -32.1% |
✅ rack-iodine
| Test | Conn | RPS | Rate | CPU/req | p99 | p99.9 | CPU | Mem | Δ RPS | Δ Mem |
|---|---|---|---|---|---|---|---|---|---|---|
| baseline | 4096 | 62,831 | — | — | — | — | 4829.1% | 4.9GiB | +0.3% | -2.0% |
| pipelined | 4096 | 2,329,452 | — | — | — | — | 6778.4% | 4.6GiB | -2.2% | ~0% |
| limited-conn | 4096 | 59,158 | — | — | — | — | 4812.8% | 4.7GiB | -0.1% | -9.6% |
| latency-1m | 1024 | 995,562 | 0.9956 | 56.06us | 837.0us | 51472.0us | 6083.9% | 4.4GiB | ~0% | -8.3% |
| latency-10k | 1024 | 9,951 | 0.9951 | 72.26us | 140.0us | 25256.0us | 95.5% | 4.3GiB | -0.2% | -10.4% |
URI.decode_www_form performs better than Rack::Utils which also supports
parsing nested params:
```ruby
require 'benchmark/ips'
require 'cgi'
require 'uri'
require 'rack'
Benchmark.ips do |x|
x.config(warmup: 2, time: 5)
query_string = "?a=14&b=54"
x.report("CGI") do
::CGI.parse(query_string)
end
x.report("URI.decode_www_form") do
URI.decode_www_form(query_string).to_h
end
x.report("Rack::Utils.parse_query") do
::Rack::Utils.parse_query(query_string)
end
x.compare!
end
```
ruby 3.4.9 (2026-03-11 revision 76cca827ab) +PRISM [arm64-darwin24]
Warming up --------------------------------------
CGI 60.058k i/100ms
URI.decode_www_form 63.568k i/100ms
Rack::Utils.parse_query 40.922k i/100ms
Calculating -------------------------------------
CGI 632.535k (± 2.4%) i/s (1.58 μs/i) - 3.183M in 5.032252s
URI.decode_www_form 667.942k (± 2.0%) i/s (1.50 μs/i) - 3.369M in 5.044006s
Rack::Utils.parse_query 417.398k (± 2.5%) i/s (2.40 μs/i) - 2.087M in 5.000076s
Comparison:
URI.decode_www_form: 667942.1 i/s
CGI: 632534.7 i/s - 1.06x slower
Rack::Utils.parse_query: 417398.1 i/s - 1.60x slower
MDA2AV
approved these changes
Sep 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
URI.decode_www_form performs better than Rack::Utils which also supports parsing nested params: