Skip to content
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

API changes: use the same function signature for package funcs #112

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

rorycl
Copy link

@rorycl rorycl commented Jan 4, 2025

Hi @mnako

I've had a chance to look at how to potentially implement new package level funcs, as set out in this PR. Let me know what you think.

Cheers,
Rory


api: split main package ParseEmail func into several variants

Split ParseEmail into three functions with the function signature

   io.Reader (Email, error)

The three functions are

  • ParseEmail (the existing main entry point)
  • ParseEmailHeaders
  • ParseEmailWithoutAttachments

ParseEmailHeadings replaces ParseHeadings that takes an Email parameter
instead of an io.Reader.

The existing ParseEmail function is renamed to parseEmail and the
processing options determined by the new processType type.

rorycl added 5 commits January 4, 2025 16:49
Split ParseEmail into three functions with the function signature

   io.Reader (Email, error)

The three functions are

   ParseEmail (the existing main entry point)
   ParseEmailHeaders
   ParseEmailWithoutAttachments

ParseEmailHeadings replaces ParseHeadings that takes an Email parameter
instead of an io.Reader.

The existing ParseEmail function is renamed to parseEmail and the
processing determined by the new processType type.
The test comparison function has also been moved from reflect.DeepEqual
to go-cmp.Equal.
@rorycl rorycl requested a review from mnako as a code owner January 4, 2025 19:27
@rorycl
Copy link
Author

rorycl commented Jan 6, 2025

I've run a quick benchmark to compare ParseEmail, ParseEmailHeaders and ParseEmailWithoutAttachments. The setup is 5 emails with ~20MB attachments each. The test is attached as performance_test.go.txt.

The results are as follows on my ancient thinkpad t470s:

rory:~/src/letters$ go test -run=Benchmark -bench=.  -benchtime=15s
goos: linux
goarch: amd64
pkg: github.com/mnako/letters
cpu: Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz
BenchmarkParseEmail-4                     	      14	1091424774 ns/op
BenchmarkParseEmailHeadersOnly-4          	    5770	   5307012 ns/op
BenchmarkParseEmailWithoutAttachments-4   	      20	 839565841 ns/op
PASS
ok  	github.com/mnako/letters	65.073s

I'm surprised that ParseEmailWithoutAttachments is only a bit over 20% faster than ParseEmail but I guess the programme is still having to read through the MIME parts. I realise this isn't a huge performance gain but it is useful for programmes such as my mailfinder programme.

@rorycl
Copy link
Author

rorycl commented Jan 6, 2025

Apologies, after looking at my work from the weekend I realise I hadn't put types into the structs.go file -- I'm not used to doing that.

I can provide a new PR after receiving comments, if any.

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.

1 participant