Skip to content

Conversation

@Tina-1300
Copy link

This PR replaces the existing Base64Decode implementation with a more optimized version :

  • Pre-allocates the output string to avoid dynamic reallocations.
  • Decodes 4 Base64 characters into 3 bytes per iteration.
  • Branchless main loop for better CPU performance.
  • Handles padding '=' efficiently after the main loop.
  • Uses a static lookup table initialized once, reducing overhead on repeated calls.

Performance improvements are noticeable for large Base64 inputs.

@COM8
Copy link
Member

COM8 commented Nov 1, 2025

@Tina-1300 thanks for submitting! I like this. Please take a look at the compilation errors. Also please use "modern" C++ features where possible like std::array.

@Tina-1300
Copy link
Author

I'll take a look. I thought the errors weren't coming from me; I thought they were from the project, that some errors had slipped through the cracks. But apparently, I must have broken something while trying to improve performance. How do I modify this PR, or rather, the code for this PR? Or do I need to create a new PR?

@Tina-1300
Copy link
Author

It's great to see you again. I thought the project was dead, so I'm glad @COM8 replied. How do you come up with such good library ideas? I've been racking my brain, but I can't find a problem to solve, and I'd love to be the creator of a well-known library like you, or (the creator of Laravel). I admire you a lot.

@COM8
Copy link
Member

COM8 commented Nov 2, 2025

I'll take a look. I thought the errors weren't coming from me; I thought they were from the project, that some errors had slipped through the cracks. But apparently, I must have broken something while trying to improve performance. How do I modify this PR, or rather, the code for this PR? Or do I need to create a new PR?

Variant 1: Push another commit to your branch: https://github.com/Tina-1300/cpr/tree/perf/base64-decode
Variant 2: Head over to here and press the pen icon. This allows you to edit the code. More details: https://docs.github.com/en/repositories/working-with-files/managing-files/editing-files

@COM8
Copy link
Member

COM8 commented Nov 2, 2025

It's great to see you again. I thought the project was dead, so I'm glad @COM8 replied. How do you come up with such good library ideas? I've been racking my brain, but I can't find a problem to solve, and I'd love to be the creator of a well-known library like you, or (the creator of Laravel). I admire you a lot.

Thanks 😅. I have to be open with you. I did not invent this lib. I just took it over a few years ago when it basically was not maintained any more and needed some large changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants