Skip to content

Commit ef38895

Browse files
gpsheadclaude
andcommitted
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>
1 parent 1e12273 commit ef38895

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Modules/binascii.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ get_binascii_state(PyObject *module)
7676
}
7777

7878

79-
static const unsigned char table_a2b_base64[] = {
79+
/* Align to 64 bytes to ensure table fits in a single L1 cache line */
80+
static const unsigned char table_a2b_base64[] Py_ALIGNED(64) = {
8081
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
8182
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
8283
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
@@ -109,7 +110,8 @@ static const unsigned char table_a2b_base64[] = {
109110
* This allows the compiler to better optimize the hot loops.
110111
*/
111112

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

115117
/* Encode 3 bytes into 4 base64 characters. */

0 commit comments

Comments
 (0)