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

replace bencoder.pyx with fastbencode #2077

Merged
merged 1 commit into from
Oct 23, 2024

Conversation

feederbox826
Copy link
Collaborator

bencoder.pyx is troublesome since it needs to be built from scratch, fastbencode is a drop-in replacement and performs much better than bencoder.pyx

import timeit

file_handle = open("target.torrent", "rb")
file_data = file_handle.read()

# bencode.pyx
# https://github.com/whtsky/bencoder.pyx
# existing stash
from bencoder import bdecode as bdecode_pyx

# fastbencode
# https://github.com/breezy-team/fastbencode
# debian
from fastbencode import bdecode as bdecode_fastbencode

# bencode.py
# https://github.com/fuzeman/bencode.py
# alpine
from bencodepy import bdecode as bdecode_bencodepy

# fast-bencode
# 

def bencode_pyx():
    bdecode_pyx(file_data)

def bencode_fastbencode():
    bdecode_fastbencode(file_data)

def bencode_bencodepy():
    bdecode_bencodepy(file_data)

def check():
    print(bdecode_pyx(file_data)[b"metadata"][b"taglist"])
    print(bdecode_fastbencode(file_data)[b"metadata"][b"taglist"])
    print(bdecode_bencodepy(file_data)[b"metadata"][b"taglist"])
check()

def benchmark():
    print(timeit.timeit(bencode_pyx, number=1000))
    print(timeit.timeit(bencode_fastbencode, number=1000))
    print(timeit.timeit(bencode_bencodepy, number=1000))
benchmark()

They all return the same result, with the speeds being

0.03148120001424104
0.007315099996048957
0.06574869999894872

and being able to drop the build requirements is very nice

@feederbox826 feederbox826 merged commit a628df2 into stashapp:master Oct 23, 2024
1 check passed
@feederbox826 feederbox826 deleted the fastbencode branch October 23, 2024 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant