Re: Preferring MemSet or memset? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Preferring MemSet or memset?
Date
Msg-id 14581.1415155297@sss.pgh.pa.us
Whole thread Raw
In response to Preferring MemSet or memset?  (Michael Paquier <michael.paquier@gmail.com>)
List pgsql-hackers
Michael Paquier <michael.paquier@gmail.com> writes:
> MemSet is an internal macro faster than the system memset for zeroing small
> word-aligned structures defined in src/include/c.h. Both are being used
> here and there with no real preference.
> An example of that is that in many code paths we have for example nulls and
> values used to build tuples, that are sometimes initialized with memset,
> other times with MemSet. Wouldn't we gain a bit of performance by switching
> to MemSet the initializations of nulls and values currently done with
> memset?

MemSet is *not* a win unless the target area is word-sized+word-aligned,
so it'd be a pretty unlikely thing for it to win on zeroing bool arrays.

In principle it could win for zeroing Datum arrays, but I don't think
I want to read code that is zeroing a Datum array with MemSet and the
adjacent bool array with memset; that's just weird, and it's unlikely
that we get enough win out of it to justify the notational inconsistency.

I keep expecting that we'll find that on modern platforms memset is a
winner across the board.  There is no reason that gcc couldn't optimize
memset calls into code as good as or better than MemSet, and I have the
impression that the compiler guys have actually put some effort into
optimizing it lately.  I'm not sure if anyone's recently redone the
tests that showed MemSet was worthwhile ...
        regards, tom lane



pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Preferring MemSet or memset?
Next
From: mariem
Date:
Subject: Convert query plan to sql query