Swap should be better done native?
martinrb at google.com
Fri Apr 2 17:37:53 PDT 2010
On Fri, Apr 2, 2010 at 16:56, Ulf Zibis <Ulf.Zibis at gmx.de> wrote:
>> No. In general, we can't assume that the target address is int-aligned,
>> and non-x86 architectures require alignment for word writes to memory.
> This should be a rare case even on non-x86 architectures.
> It generally should only happen, if the offset of a sliced buffer is not
> aligned to it's value size.
> Fresh allocated buffers should be always properly aligned (hopefully).
> I wanted to say, that 4 put(byte) can be replaced by one put(int), but would
> perform likely worse in the rare case of unaligned position pointer.
> E.g. this can happen frequently on UTF-8 coder, but could always be checked.
I don't think unaligned access is rare.
Perhaps because I've spent too much time in the zip implementation.
Ulf, you could start a project to find all the places where we could replace
unaligned reads on x86 with int reads. E.g. in zip_util.h I see
#define CH(b, n) (((unsigned char *)(b))[n])
#define SH(b, n) (CH(b, n) | (CH(b, n+1) << 8))
#define LG(b, n) ((SH(b, n) | (SH(b, n+2) << 16)) &0xffffffffUL)
#define LL(b, n) (((jlong)LG(b, n)) | (((jlong)LG(b, n+4)) << 32))
#define GETSIG(b) LG(b, 0)
by conditionally using short, int, or long reads,
you could speed up zip file reading significantly on x86.
Which seems like an important optimization.
More information about the nio-dev