Re: Avoid unecessary MemSet call (src/backend/utils/cache/relcache.c)

Ranier Vilela <ranier.vf@gmail.com>

From: Ranier Vilela <ranier.vf@gmail.com>
To: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Cc: Justin Pryzby <pryzby@telsasoft.com>, David Rowley <dgrowleyml@gmail.com>, Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2022-07-07T17:01:25Z
Lists: pgsql-hackers

Attachments

Em qui., 7 de jul. de 2022 às 09:45, Ranier Vilela <ranier.vf@gmail.com>
escreveu:

> Em qui., 7 de jul. de 2022 às 08:00, Peter Eisentraut <
> peter.eisentraut@enterprisedb.com> escreveu:
> >diff --git a/src/backend/access/transam/twophase.c
> b/src/backend/access/transam/twophase.c
> >index 41b31c5c6f..803d169f57 100644
> >--- a/src/backend/access/transam/twophase.c
> >+++ b/src/backend/access/transam/twophase.c
> >@@ -780,8 +780,8 @@ pg_prepared_xact(PG_FUNCTION_ARGS)
> >  {
> >  GlobalTransaction gxact = &status->array[status->currIdx++];
> >  PGPROC   *proc = &ProcGlobal->allProcs[gxact->pgprocno];
> >- Datum values[5];
> >- bool nulls[5];
> >+ Datum values[5] = {0};
> >+ bool nulls[5] = {0};
>
> values variable no initialization or MemSet needed.
>
> diff --git a/src/backend/access/transam/xlogfuncs.c
> b/src/backend/access/transam/xlogfuncs.c
> index 02bd919ff6..61e0f4a29c 100644
> --- a/src/backend/access/transam/xlogfuncs.c
> +++ b/src/backend/access/transam/xlogfuncs.c
> @@ -106,8 +106,8 @@ pg_backup_stop(PG_FUNCTION_ARGS)
>  {
>  #define PG_STOP_BACKUP_V2_COLS 3
>   TupleDesc tupdesc;
> - Datum values[PG_STOP_BACKUP_V2_COLS];
> - bool nulls[PG_STOP_BACKUP_V2_COLS];
> + Datum values[PG_STOP_BACKUP_V2_COLS] = {0};
> + bool nulls[PG_STOP_BACKUP_V2_COLS] = {0};
>
> Same, values variable no initialization or MemSet needed.
>
> diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c
> index 5f1726c095..17ff617fba 100644
> --- a/src/backend/catalog/aclchk.c
> +++ b/src/backend/catalog/aclchk.c
> @@ -1188,9 +1188,6 @@ SetDefaultACL(InternalDefaultACL *iacls)
>   Acl   *old_acl;
>   Acl   *new_acl;
>   HeapTuple newtuple;
> - Datum values[Natts_pg_default_acl];
> - bool nulls[Natts_pg_default_acl];
> - bool replaces[Natts_pg_default_acl];
>   int noldmembers;
>   int nnewmembers;
>   Oid   *oldmembers;
> @@ -1341,13 +1338,11 @@ SetDefaultACL(InternalDefaultACL *iacls)
>   }
>   else
>   {
> + Datum values[Natts_pg_default_acl] = {0};
> + bool nulls[Natts_pg_default_acl] = {0};
>
> replaces, can be reduced more one level.
>
> line 1365:
> else
> {
>          +bool replaces[Natts_pg_default_acl] = {0};
>           defAclOid = ((Form_pg_default_acl) GETSTRUCT(tuple))->oid;
>
> please, wait a minute, I will produce a new version of your patch, with
> some changes for your review.
>
Attached the v1 of your patch.
I think that all is safe to switch MemSet by {0}.

regards,
Ranier Vilela

Commits

  1. Replace many MemSet calls with struct initialization

  2. Change some unnecessary MemSet calls

  3. Avoid unnecessary MemSet call