Vectorization of some functions and improving pg_list interface

From: Maxim Orlov <orlovmg(at)gmail(dot)com>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Vectorization of some functions and improving pg_list interface
Date: 2023-08-24 14:07:29
Message-ID: CACG=ezasBfMiXgx=O_n3oigCk0JADG6RKimrzj7yDPGqQG9MSw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi!

Recently, I've been playing around with pg_lists and realize how annoying
(maybe, I was a bit tired) some stuff related to the lists.
For an example, see this code
List *l1 = list_make4(1, 2, 3, 4),
*l2 = list_make4(5, 6, 7, 8),
*l3 = list_make4(9, 0, 1, 2);
ListCell *lc1, *lc2, *lc3;

forthree(lc1, l1, lc2, l2, lc3, l3) {
...
}

list_free(l1);
list_free(l2);
list_free(l3);

There are several questions:
1) Why do I need to specify the number of elements in the list in the
function name?
Compiler already knew how much arguments do I use.
2) Why I have to call free for every list? I don't know how to call it
right, for now I call it vectorization.
Why not to use simple wrapper to "vectorize" function args?

So, my proposal is:
1) Add a simple macro to "vectorize" functions.
2) Use this macro to "vectorize" list_free and list_free_deep functions.
3) Use this macro to "vectorize" bms_free function.
4) "Vectorize" list_makeN functions.

For this V1 version, I do not remove all list_makeN calls in order to
reduce diff, but I'll address
this in future, if it will be needed.

In my view, one thing still waiting to be improved if foreach loop. It is
not very handy to have a bunch of
similar calls foreach, forboth, forthree and etc. It will be ideal to have
single foreach interface, but I don't know how
to do it without overall interface of the loop.

Any opinions are very welcome!

--
Best regards,
Maxim Orlov.

Attachment Content-Type Size
v1-0002-Make-use-of-vectorized-lists_free-and-lists_free_.patch application/octet-stream 10.7 KB
v1-0004-vectorize-list_make-functions.patch application/octet-stream 9.1 KB
v1-0001-Add-lists_free-and-lists_free_deep.patch application/octet-stream 1.7 KB
v1-0003-Make-use-of-vectorized-bmss_free-function.patch application/octet-stream 6.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Chapman Flack 2023-08-24 14:19:29 Re: Vectorization of some functions and improving pg_list interface
Previous Message Heikki Linnakangas 2023-08-24 14:05:46 Re: Use FD_CLOEXEC on ListenSockets (was Re: Refactoring backend fork+exec code)