koodaamo / tnefparse

a TNEF decoding library written in python, without external dependencies
GNU Lesser General Public License v3.0
49 stars 37 forks source link

speed bottleneck within decode_mapi #20

Closed TZanke closed 5 years ago

TZanke commented 6 years ago

Hello,

today i had a problem with a customer tnef mail. It took around 150ms to call decode_mapi. Because it is called several times within tnefparse and within my code, it took around 2500ms to handle a request to this file.

I searched for the bottleneck with cProfile and found the problem:

In decode_mapi the var num_vals is a int bigger then several millions. Python will generate a list this big... Solution: do not generate this big list, just use a iterator: xrange()

Speed change: 2500ms > 60ms

TZanke commented 6 years ago

I do not know how you handle python2/3 compatibility, so i do not implement a patch atm.

http://python-future.org/compatible_idioms.html#xrange

jrideout commented 5 years ago

This was fixed in 0898eb8

petri commented 5 years ago

thx @jrideout