Constifying numeric.c's local vars

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Constifying numeric.c's local vars
Date: 2017-09-10 23:21:54
Message-ID: 20170910232154.asgml44ji2b7lv3d@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

For JIT inlining currently functions can't be inlined if they reference
non-constant static variables. That's because there's no way, at least
none I know of, to link to the correct variable, instead of duplicating,
the linker explicitly renames symbols after all (that's the whole point
of static vars). There's a bunch of weird errors if you ignore that ;)

One large user of unnecessary non-constant static variables is
numeric.c. More out of curiosity - numeric is slow enough in itself to
make inlining not a huge win - I converted it to use consts.

before:
andres(at)alap4:~/build/postgres/dev-assert/vpath$ size --format=SysV src/backend/utils/adt/numeric.o |grep -v debug|grep -v '^.group'
src/backend/utils/adt/numeric.o :
section size addr
.text 68099 0
.data 64 0
.bss 2 0
.rodata 4256 0
.data.rel.local 224 0
.comment 29 0
.note.GNU-stack 0 0
.eh_frame 5976 0
Total 395590

after:

$ size --format=SysV src/backend/utils/adt/numeric.o |grep -v debug|grep -v '^.group'
src/backend/utils/adt/numeric.o :
section size addr
.text 68108 0
.data 0 0
.bss 0 0
.rodata 4288 0
.data.rel.ro.local 224 0
.comment 29 0
.note.GNU-stack 0 0
.eh_frame 5976 0
Total 395586

Nicely visible that the data is moved from a mutable segment to a
readonly one.

It's a bit ugly that some consts have to be casted away in the constant
definitions, but aside from just inlining the values, I don't quite see
a better solution?

Leaving JIT aside, I think stuff like this is worthwhile on its own...

Greetings,

Andres Freund

Attachment Content-Type Size
0001-Constify-numeric.c.patch text/x-diff 21.0 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2017-09-10 23:40:14 Automatic testing of patches in commit fest
Previous Message Peter Geoghegan 2017-09-10 23:03:12 Re: The case for removing replacement selection sort