Re: plenty code is confused about function level static - Mailing list pgsql-hackers

From Ranier Vilela
Subject Re: plenty code is confused about function level static
Date
Msg-id CAEudQAoB_2_ejJUFz=LFX7_nK6SgHFei_+cmoa4X43UfPp4gsA@mail.gmail.com
Whole thread Raw
In response to plenty code is confused about function level static  (Andres Freund <andres@anarazel.de>)
Responses Re: plenty code is confused about function level static
List pgsql-hackers
On 18/04/2024 00:39, Andres Freund wrote:

>We have a fair amount of code that uses non-constant function level static
>variables for read-only data. Which makes little sense - it prevents the
>compiler from understanding

>a) that the data is read only and can thus be put into a segment that's shared
>between all invocations of the program
>b) the data will be the same on every invocation, and thus from optimizing
>based on that.

>The most common example of this is that all our binaries use
>static struct option long_options[] = { ... };
>which prevents long_options from being put into read-only memory.

+1 static const allows the compiler to make additional optimizations.

>There are lots of places that could benefit from adding 'static
>const'.

I found a few more places.

Patch 004

The opposite would also help, adding static.
In these places, I believe it is safe to add static,
allowing the compiler to transform into read-only, definitively.

Patch 005

best regards,

Ranier Vilela

Attachment

pgsql-hackers by date:

Previous
From: shveta malik
Date:
Subject: Re: promotion related handling in pg_sync_replication_slots()
Next
From: Aleksander Alekseev
Date:
Subject: Re: Trigger violates foreign key constraint