Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Align base64 tables to 64-byte cache line boundaries
Add Py_ALIGNED(64) to both lookup tables to ensure each fits
within a single L1 cache line, reducing potential cache misses
during encoding/decoding loops.

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
  • Loading branch information
gpshead and claude committed Dec 29, 2025
commit ef38895ff3208ed439ba1c63e7a26ea1c77a72ca
6 changes: 4 additions & 2 deletions Modules/binascii.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ get_binascii_state(PyObject *module)
}


static const unsigned char table_a2b_base64[] = {
/* Align to 64 bytes to ensure table fits in a single L1 cache line */
Comment thread
gpshead marked this conversation as resolved.
Outdated
static const unsigned char table_a2b_base64[] Py_ALIGNED(64) = {
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
Expand Down Expand Up @@ -109,7 +110,8 @@ static const unsigned char table_a2b_base64[] = {
* This allows the compiler to better optimize the hot loops.
*/

static const unsigned char table_b2a_base64[] =
/* Align to 64 bytes to ensure table fits in a single L1 cache line */
static const unsigned char table_b2a_base64[] Py_ALIGNED(64) =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

/* Encode 3 bytes into 4 base64 characters. */
Expand Down
Loading