Skip to content

Conversation

@bogdan
Copy link
Contributor

@bogdan bogdan commented Mar 10, 2012

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
Copy link
Owner

mikel commented Nov 17, 2012

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants