pgsql.hackers
[Top] [All Lists]

Is it really such a good thing for newNode() to be a macro?

Subject: Is it really such a good thing for newNode() to be a macro?
From: Tom Lane
Date: Tue, 26 Aug 2008 14:57:04 -0400
Newsgroups: pgsql.hackers

I happened to be looking at nodes.h and started wondering just how
sane this coding really is:

extern PGDLLIMPORT Node *newNodeMacroHolder;

#define newNode(size, tag) \
( \
    AssertMacro((size) >= sizeof(Node)),        /* need the tag, at least */ \
    newNodeMacroHolder = (Node *) palloc0fast(size), \
    newNodeMacroHolder->type = (tag), \
    newNodeMacroHolder \
)

Given that we're calling palloc, it's not clear that saving one level of
function call is really buying much; and what it's costing us is a store
to a global variable that the compiler has no way to optimize away.
On a lot of platforms, accessing global variables isn't especially
cheap.  Also, considering that palloc0fast is a nontrivial macro, and
that there are a LOT of uses of newNode(), we're paying rather a lot of
code space for a pretty dubious savings.

So I'm tempted to get rid of this and just make newNode() an out-of-line
function.

Thoughts?

                        regards, tom lane

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy