[New-bugs-announce] [issue15138] base64.urlsafe_b64**code are too slow

Guido van Rossum report at bugs.python.org
Fri Jun 22 17:00:00 CEST 2012

New submission from Guido van Rossum <guido at python.org>:

This bug is still present in Python 3.3.  Some people use urlsafe strings *a lot*. And they find that the (obvious) implementation in base64.py is way too slow.  In fact, I found myself writing the following a few times in App Engine libraries:

    # This is 3-4x faster than urlsafe_b64decode()                   
    urlsafe = base64.b64encode(<arg>)
    return urlsafe.rstrip('=').replace('+', '-').replace('/', '_')

Someone from YouTube told me they patch the stdlib for the same reason (they claim their solution is 10x faster).

IIUC the cause of the slowness is the (mostly irrelevant) generality in b64encode and the _translate() function.

components: Library (Lib)
keywords: easy
messages: 163420
nosy: gvanrossum
priority: normal
severity: normal
stage: needs patch
status: open
title: base64.urlsafe_b64**code are too slow
type: performance
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list