python / cpython

The Python programming language
https://www.python.org
Other
63.39k stars 30.35k forks source link

imaplib.IMAP4_SSL: changed quadratic read() code to linear #40268

Closed 31475d12-5c49-44cd-a6d0-ae9a9c0209a4 closed 20 years ago

31475d12-5c49-44cd-a6d0-ae9a9c0209a4 commented 20 years ago
BPO 956394
Files
  • patch.txt: imaplib patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = None closed_at = created_at = labels = ['library'] title = 'imaplib.IMAP4_SSL: changed quadratic read() code to linear' updated_at = user = 'https://bugs.python.org/cwraith' ``` bugs.python.org fields: ```python activity = actor = 'tinolange' assignee = 'pierslauder' closed = True closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'c_wraith' dependencies = [] files = ['5974'] hgrepos = [] issue_num = 956394 keywords = ['patch'] message_count = 4.0 messages = ['45997', '45998', '45999', '46000'] nosy_count = 3.0 nosy_names = ['pierslauder', 'tinolange', 'c_wraith'] pr_nums = [] priority = 'normal' resolution = 'accepted' stage = None status = 'closed' superseder = None type = None url = 'https://bugs.python.org/issue956394' versions = [] ```

    31475d12-5c49-44cd-a6d0-ae9a9c0209a4 commented 20 years ago

    read() in imaplib.IMAP4_SSL used string concatenation with += in a loop. This lead to exceptionally poor performance retreiving large email messages.

    Changed both read() and readline() in IMAP4_SSL to aggregate string fragments in a list, then join the elements of the list before returning them. This replaces an O(n^2) algorithm with an O(n) algorithm, for a significant speed increase when retreiving large email messages.

    5a406dc1-17ed-436a-b95f-f503f6ec7b5a commented 20 years ago

    Logged In: YES user_id=196212

    Thanks for your changes - will check them in!

    5a406dc1-17ed-436a-b95f-f503f6ec7b5a commented 20 years ago

    Logged In: YES user_id=196212

    changes checked in.

    271dffe4-626f-43cb-87da-0427ac78c2e5 commented 20 years ago

    Logged In: YES user_id=212920

    cool idea, Carl! This is code to remember! Thanks for submitting that!