Mail::Header: resolve performance issue #369

Merged
merged 1 commit into from Nov 17, 2012

Projects

None yet

2 participants

@bogdan

Mail::Header#charset is called pretty often during header parser work.
If there are large amount of headers #[] is pretty slow.

There is already @charset variable, but it doesn't speed up the charset method. This patch makes headers parsing faster by keeping @charset variable always up to date and speeding up the charset method .

Benchmark code:

Mail::Header.new("X-SubscriberID: 345\n" * 100)

Benchmark: https://gist.github.com/6b84d985c4e2b29dbb80

Result (with patch and without patch):

Running benchmark with current working tree
Checkout HEAD^
Running benchmark with HEAD^
Checkout to previous HEAD again

                    user     system      total        real
----------------------------------headers parsing when long
After patch:    0.100000   0.000000   0.100000 (  0.089926)
Before patch:   0.700000   0.000000   0.700000 (  0.697444)

----------------------------------headers parsing when tiny
After patch:    0.000000   0.000000   0.000000 (  0.009930)
Before patch:   0.020000   0.000000   0.020000 (  0.024283)

---------------------------------headers parsing when empty
After patch:    0.010000   0.000000   0.010000 (  0.002160)
Before patch:   0.000000   0.000000   0.000000 (  0.002354)
@mikel
Owner

Great work, thanks :)

@mikel mikel merged commit 4668309 into mikel:master Nov 17, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment