Skip to content

base64: optimize b16decode - #157310

Merged
methane merged 2 commits into
python:mainfrom
methane:codex/pr-base16-decode
Sep 11, 2026
Merged

base64: optimize b16decode#157310
methane merged 2 commits into
python:mainfrom
methane:codex/pr-base16-decode

Conversation

@methane

@methane methane commented Sep 11, 2026

Copy link
Copy Markdown
Member

When ignorechars is empty, we already know that [a-f] is not present in the byte string, so we skip the call to str.translate(). Even when str.translate() does not modify the string at all, it internally creates a temporary bytes object, so this saves a small amount of time.

@methane

methane commented Sep 11, 2026

Copy link
Copy Markdown
Member Author

bm_base64 in pyperformance:

base16_small: Mean +- std dev: [b16-main-commonloop] 278 us +- 1 us -> [b16-changed-commonloop] 219 us +- 2 us: 1.27x faster
base16_large: Mean +- std dev: [b16-main-commonloop] 6.05 ms +- 0.10 ms -> [b16-changed-commonloop] 4.10 ms +- 0.06 ms: 1.48x faster

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4298ee9383

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Lib/base64.py
if b in s and b not in ignorechars:
raise binascii.Error('Non-base16 digit found')
s = s.translate(None, delete=b'abcdef')
if ignorechars:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check the actual byte length before skipping translation

When ignorechars is a nonempty bytes subclass whose __bool__ returns false, this condition skips the translation even though the lowercase characters must be removed. For example, with such a subclass containing b'a', b16decode(b'aB', ignorechars=...) now decodes the lowercase a as a hex digit and returns b'\xab'; previously a was ignored and the remaining odd digit raised binascii.Error. Normalize bytes subclasses or otherwise test the underlying buffer's emptiness without invoking overridable truthiness.

AGENTS.md reference: AGENTS.md:L16-L16

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-11T12:25:24.391043Z 4298ee9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. 👍

@methane
methane merged commit b6e8088 into python:main Sep 11, 2026
58 checks passed
@methane
methane deleted the codex/pr-base16-decode branch September 11, 2026 14:09
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Sep 12, 2026
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