Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

email.message_from_bytes heavy memory use #115512

Open
Labels
stdlibPython modules in the Lib dirtopic-emailtype-bugAn unexpected behavior, bug, or error
@cnicodeme

Description

@cnicodeme

Bug report

Bug description:

Hi!

Investigating some memory issues on my lamdba, I discovered an odd usage coming fromemail.message_from_bytes

When opening an .eml that contains close to no text but a 30Mb attachment, the memory usage jumps to +238Mb !
9 times the size of the file!!

Here's what was my tests:

fromemailimportmessage_from_bytesimportresourceprint('Init ram: {}kb'.format(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss))data=Nonewithopen('file.eml','rb')asf:data=f.read()print('File loaded: {}kb'.format(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss))print('    (file size: {}kb)'.format(len(data)/1024))mail=message_from_bytes(data)print('After message_from_bytes: {}kb'.format(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss))

And the output:

Init ram: 7168kbFile loaded: 37120kb    (file size: 29900kb)After message_from_bytes: 279296kb

The EML in question contains an attachment (a CSV file) encoded in Base64. I suspect thatBytesParser is converting that content to binary data, but I find it surprising that doing this takes 9 times the filesize.
Wouldn't it be faster and more efficient to convert that only when accessing, and having a way to not convert it at all (getting it raw, in base64) ?

(Maybe there is already and I missed it?)

I tested this in:

  • Python 3.10.13
  • Python 3.12.1

And got the same results.

CPython versions tested on:

3.10

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtopic-emailtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp