serhiy-storchaka · GitHub

Base64 decoding was optimized in #124951. But the optimization only worked to the first ignored character. The proposed PR makes it used even if there are some ignored characters (e.g. multiline data).

Examples:

$ ./python -m timeit -s 'import binascii; a = (b"a"*76+b"\n")*1000' 'binascii.a2b_base64(a)'
baseline:  10000 loops, best of 5: 37.7 usec per loop
optimized: 10000 loops, best of 5: 20.2 usec per loop
$ ./python -m timeit -s 'import binascii; a = (b"a"*76+b"\n")*1000' 'binascii.a2b_base64(a, ignorechars=b" \t\n\r\v")'
baseline:  5000 loops, best of 5: 42.7 usec per loop
optimized: 10000 loops, best of 5: 21.3 usec per loop

For comparison, Base64 decoding without ignored characters:

$ ./python -m timeit -s 'import binascii; a = (b"a"*76)*1000' 'binascii.a2b_base64(a)'
20000 loops, best of 5: 17.3 usec per loop

Linked PRs

Read the original on github.com ↗