Skip to content

perf(util): encode Base64 in three-byte blocks - #1045

Merged
wgtmac merged 2 commits into
apache:mainfrom
fallintoplace:perf/base64-block-encoding-20261020
Oct 21, 2026
Merged

wgtmac merged 2 commits into
apache:mainfrom
fallintoplace:perf/base64-block-encoding-20261020

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

What

  • Encode Base64 input in 3-byte blocks.

Why

  • Reduce per-byte work during encoding.

Implementation

  • Pre-size the output and write encoded blocks directly.
  • Keep standard and URL-safe output.

Benchmark

  • Standalone GCC 14 -O3: 1 KiB 2.427 → 0.811 µs (3.0x); 16 KiB 37.55 → 13.49 µs (2.8x).

@zhjwpku zhjwpku left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactor looks clean and more understandable to me, thanks for the PR.

Comment thread src/iceberg/util/base64.cc Outdated
if (remainder == 2) {
output[out++] = alphabet[(block >> 6) & 0x3F];
}
if (pad) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: seems we can delete this condition wrapper since the output_size is exact.

@zhjwpku zhjwpku added the ready to merge This PR has been approved and it is ready to merge. label Oct 20, 2026
@wgtmac wgtmac removed the ready to merge This PR has been approved and it is ready to merge. label Oct 21, 2026
@wgtmac
wgtmac merged commit c6ccd05 into apache:main Oct 21, 2026
15 checks passed
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.

3 participants