Skip to content

Improve performance of Message#find_attachment #825

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

bpot
Copy link
Contributor

@bpot bpot commented Nov 1, 2014

This is faster because we,

  • Don't trigger exceptions for flow control.
  • Retrieve each header only once (at most).

The exceptions this was throwing were particularly expensive for us on jruby. This change cut our mail processing time in half for a particular task.

The tests are passing with this change but it's possible that the rescues in the previous code were catching other exceptions that will now bubble up. We could add a rescue to find_attachment_filename to catch those.

- Don't trigger exceptions for flow control.
- Retrieve each header only once (at most).
end

content_location_header = header[:content_location]
if content_location_header && (filename = content_location_header.location)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about:

def find_attachment_filename
  try_to_call(header[:content_type], :filename) || 
    try_to_call(header[:content_disposition], :filename) || 
    try_to_call(header[:content_location], :location)
end

def try_to_call(object, method)
  object && object.send(method)
end

@grosser
Copy link
Contributor

grosser commented Nov 24, 2014

👍 causing and catching exceptions is super-messy

@jeremy @bf4

@bpot
Copy link
Contributor Author

bpot commented Dec 2, 2014

@grosser cleaned up the duplication in #find_attachment_filename. I like to avoid using #send if possible.

field.location
when ContentTypeField, ContentDispositionField
field.filename
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else raise ArgumentError ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree in principle, but it would be a change in behavior. I'd rather handle that separately.

@grosser
Copy link
Contributor

grosser commented Dec 2, 2014

@jeremy @bf4

@bf4
Copy link
Contributor

bf4 commented Dec 2, 2014

Is there a benchmark you used that we can run to test against regressions?

@bpot
Copy link
Contributor Author

bpot commented Dec 2, 2014

@bf4 I don't have anything that's easily extractable, I was profiling an application.

I agree a benchmark suite would be really useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants