Skip to content

feat: improve efficiency of the decryptor#121

Merged
devgianlu merged 1 commit intodevgianlu:masterfrom
aykevl:perf-decryptor-2
Oct 12, 2024
Merged

feat: improve efficiency of the decryptor#121
devgianlu merged 1 commit intodevgianlu:masterfrom
aykevl:perf-decryptor-2

Conversation

@aykevl
Copy link
Copy Markdown
Contributor

@aykevl aykevl commented Oct 7, 2024

The decryptor was using up a lot of time. For a ~10min song it took about twice the time that it took to run the Vorbis decoder and this time would only go up considering the exponential nature of the loop.

But actually, all it did was count up a number. This can be done using a simple addition instead of a complicated loop. Hence this patch changes the loop to a simple addition.

It is 32-bits at the moment, which means it would overflow with a stream that's 64GB 48GB big. This is entirely fixable if needed, but 48GB seems like an unlikely large stream. Updated to be 64 bits to make me feel better, this is extremely unlikely to ever overflow.

This replaces #120.

@aykevl
Copy link
Copy Markdown
Contributor Author

aykevl commented Oct 10, 2024

Updated:

  • Using binary.BigEndian instead of manually extracting/writing the individual bytes.
  • Using a 64-bit counter instead of a 32-bit counter. This won't overflow with any reasonable stream size (it will only overflow after decrypting a stream that's more than 20 exabytes long).
  • Improved the comment to explain why this is safe to do.

The decryptor was using up a lot of time. For a ~10min song it took
about twice the time that it took to run the Vorbis decoder and this
time would only go up considering the exponential nature of the loop.

But actually, all it did was count up a number. This can be done by a
simple addition instead of a complicated loop. Hence this patch changes
the loop to a simple addition.
@devgianlu devgianlu merged commit cbdc27a into devgianlu:master Oct 12, 2024
@devgianlu
Copy link
Copy Markdown
Owner

Love it!

@aykevl aykevl deleted the perf-decryptor-2 branch October 15, 2024 17:18
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.

2 participants