utdemir / bencoder

A simple bencode decoder-encoder library in pure Python.
Creative Commons Zero v1.0 Universal
31 stars 5 forks source link

track string index for big speedup #4

Open xwang1498 opened 7 months ago

xwang1498 commented 7 months ago

Hi Utku,

Thank you for this library.

I noticed that the string slicing (copying) was really slowing things down, particularly when parsing a larger file (such as hpcalc.org's 2022 snapshot torrent).

This change tracks an index in the string instead of slicing it. This improves performance by 20-70x for me on the big torrent file.

I tried to retain your code's simple elegance while speeding things up.

Tested on Python 2.7 and 3.9.