Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Mail::Header: resolve performance issue #369

Merged
merged 1 commit into from
Nov 17, 2012
Merged

Mail::Header: resolve performance issue #369

merged 1 commit into from
Nov 17, 2012

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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants