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

Sending mail with large attachement consumes lots of memory #93

Open
jurajw opened this issue Mar 28, 2018 · 5 comments
Open

Sending mail with large attachement consumes lots of memory #93

jurajw opened this issue Mar 28, 2018 · 5 comments

Comments

@jurajw
Copy link

jurajw commented Mar 28, 2018

Observed on 3.5.0.

Sending a mail with a single 3_000_000 bytes attachment requires ~ 27_000_000 bytes of heap. Based on my observation following is happening:

  1. An AttachmentPart instance is created for the attachment. In the constructor the buffer is base64 encoded into a ~ 4_000_000 characters long string. On JDK8 this is ~ 8_000_000 bytes in the heap.

  2. A MultiPart instance is created for the AttachmentPart.
    a. The AttachmentPart header is concatenated with the base64 data.
    b. The copy is appended into a StringBuilder.
    c. StringBuilder#toString is called and the result is set to MultiPart#part.

  3. MultiPart#headers is set.

  4. MultiPart#toString is called.

In 2a, 2b, 2c and 4 the base64 data is copied.

@jurajw
Copy link
Author

jurajw commented Mar 28, 2018

I have been prototyping changes such that:

  1. base64 encoding is performed lazily line-by-line (by exposing an Iterator).
  2. No copies are created (iterators are concatenated).

Is there interest in a patch?

@pmlopes
Copy link
Member

pmlopes commented Mar 31, 2018

@jurajw I think it would be interesting to have such encoder not just for mail but for json in Vertx too. Since we support a few extra RFC for the json implementation which cover temporal types and base64 I can imagine that such encoder would reduce the memory usage there too.

Perhaps you could provide a pull request and we could continue the conversation there?

@vietj
Copy link
Contributor

vietj commented May 3, 2018

there has been contributions recently in vertx-web-client for this, perhaps some of its classes should be moved to vertx-core ?

@jurajw
Copy link
Author

jurajw commented May 3, 2018

@vietj Can you point me to the relevant vertx-web-client changes?

@vietj
Copy link
Contributor

vietj commented May 3, 2018 via email

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

No branches or pull requests

3 participants