Re: Faster StrNCpy - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Faster StrNCpy
Date
Msg-id 25223.1159885218@sss.pgh.pa.us
Whole thread Raw
In response to Re: Faster StrNCpy  ("Zeugswetter Andreas DCP SD" <ZeugswetterA@spardat.at>)
Responses Another aspect of set_ps_display ()  ("Strong, David" <david.strong@unisys.com>)
List pgsql-hackers
"Zeugswetter Andreas DCP SD" <ZeugswetterA@spardat.at> writes:
>> I'm still interested to experiment with MemSet-then-strlcpy 
>> for namestrcpy, but given the LENCPY results this may be a loser too.

> Um, why not strlcpy then MemSet the rest ?

Two reasons:

* The main point is to do the zeroing using word-wide operations, and if
you do the above then memset will probably be facing a zeroing request
that is neither word-aligned nor word-length.  It may be able to recover
(doing it partly byte-wide and partly word-wide), but this will easily
eat up the time savings of skipping the first couple words.

* On compilers that treat memset as a builtin, there are significant
advantages to doing memset with a constant length: the compiler might
be able to unroll the loop entirely.  (I was annoyed to find that FC5's
gcc on x86_64 seems to understand very well how to inline a constant
length memcpy, but not memset :-(.)

I did actually do some experiments with the above yesterday, and found
that it was a significant win on an old x86 (with about a 10-byte source
string) but about a wash on newer architectures.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: [PATCHES] Generic Monitoring Framework with DTrace patch
Next
From: Tom Lane
Date:
Subject: Re: Faster StrNCpy