Re: Base64 decode/encode performance - Mailing list pgsql-hackers

From Marko Kreen
Subject Re: Base64 decode/encode performance
Date
Msg-id e51f66da0809100731q408287b5r582f17b7b37fe7a4@mail.gmail.com
Whole thread Raw
In response to Base64 decode/encode performance  (Gaetano Mendola <mendola@gmail.com>)
Responses Re: Base64 decode/encode performance  (Mark Mielke <mark@mark.mielke.cc>)
List pgsql-hackers
On 9/10/08, Gaetano Mendola <mendola@gmail.com> wrote:
>  I have been experimenting with some base64 encoding/decoding implementation.
>
>  I find out that the one at http://code.google.com/p/stringencoders is the best
>  obtaining a 1.3 speedup vs the postgres one.
>
>  Do you think is worth to submit a patch that replaces the postgres base64 implementation
>  with this one?

(Note: the b64encode there reads 3 chars at a time, b64decode int32
at a time.)

There are 2 killer problems:

- decode does not seem to handle architectures that segfault on unaligned int32 accesses.
- decode does not allow whitespace in input string.

If those are fixed it's question of if the 1.3x speed if worth more
complex code with big lookup tables.

If you want to optimize, it seems more worthwhile to add additional
loop to current code that reads 3 or 4 chars at a time, before the
current single-char loop.  The decode loop may thus even optimize
to int32 fetching on x86/64 with reasonable compiler.  Handling
whitespace with such code is doable, but will the code be clear enough?

-- 
marko


pgsql-hackers by date:

Previous
From: Zdenek Kotala
Date:
Subject: Re: using hash index when BETWEEN is specified
Next
From: Ron Mayer
Date:
Subject: Re: [PATCH] Cleanup of GUC units code