go-gomail / gomail

The best way to send emails in Go.
MIT License
4.33k stars 573 forks source link

Free additional buffers #31

Closed isaldana closed 9 years ago

alexcesaro commented 9 years ago

I don't like complicating the API with this kind of functions. Have you run into performance issues? Gomail is not yet optimized for sending big volumes of emails (see #10 in particular).

isaldana commented 9 years ago

Yes, in our case our bodies are much bigger than anything else and there is an opportunity to reuse those buffers. What about having something like a Reset() function that allows you to reset all data and reuse the Message instance similar to how bufio.Reader works: http://golang.org/pkg/bufio/#Reader.Reset?

alexcesaro commented 9 years ago

Yes that is exactly what I have been thinking. Could you update the PR and add some docs to the new function?

isaldana commented 9 years ago

Ok this is the first try based on your feedback. I added the Reset() method to BenchmarkFull() and it runs 10% faster:

$ go test -run=XXX -bench=.
PASS
BenchmarkFull      20000         93349 ns/op

Before

$ go test -run=XXX -bench=.
PASS
BenchmarkFull      10000        103005 ns/op
alexcesaro commented 9 years ago

I'm in holiday for two weeks, I will have a look when I am back.

alexcesaro commented 9 years ago

Hello, sorry for the delay.

I worked on Gomail v2 meanwhile which will be far more efficient than Gomail v1: messages are streamed directly to the SMTP (the whole message is not buffered into memory anymore), many messages can be sent on the same SMTP connection, it is easy to use postfix to send emails, etc.

I also included the Reset() method.

See the doc or the Readme for examples.

Feel free to try it and give your feedback.