Speeding Up Bitmapset

From: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Speeding Up Bitmapset
Date: 2023-06-25 12:28:36
Message-ID: CAEudQAqZSb9bkXsUG2ehnZqZ6waumuF8j5p+whsgWiRGb_Sbfg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Yuya Watari presented a series of patches, with the objective of improving
the Bitmapset [1].
After reading through the patches, I saw a lot of good ideas and thought
I'd help.
Unfortunately, my suggestions were not well received.
Even so, I decided to work on these patches and see what could be improved.

Eventually it arrived at the attached patch, which I'm naming v7, because
of the sequence it had established.

Those who follow the other thread will see that the original patch actually
improves the overall performance of Bitmapset,
but I believe there is room for further improvement.

I ran the same tests provided by Yuya Watari and the results are attached.
Both on Windows and Linux Ubuntu, the performance of v7 outperforms head
and v4.
At Ubuntu 64 bits:
v7 outperforms v4 by 29% (Query A)
v7 outperforms v4 by 19% (Query B)

At Windows 64 bits:
v7 outperforms v4 by 22% (Query A)
v7 outperforms v4 by 33% (Query B)

I believe patch v7 leaves the Bitmapset in good shape and readable, well
written.

Questions arose regarding possible regression when using the backward loop,
but in all the tests I ran this version with backward performed better.
Possibly because of the smaller number of variables and the efficient test
(--i <= 0), which both the msvc and gcc compilers successfully optimize.

If the v7 version with loop forward performs worse on x86_64 cpus,
I don't see how it will perform better on other architectures, since the
vast majority of modern ones and with great cache support.

Another question is related to an alleged "spurius test", whose objective
is to avoid test and set instructions for each element of the array.
Again I ran the tests without the test and the performance was worse,
showing its value.

regards,
Ranier Vilela

[1]
https://www.postgresql.org/message-id/CAJ2pMkZ0HfhfA0QNa_msknL%3D_-PavZmPHRWnW7yOb3_PWUoB%2Bg%40mail.gmail.com

Attachment Content-Type Size
bench_windows_bitmapset.txt text/plain 1.3 KB
speeding-up-bitmapset-v7.patch application/octet-stream 22.0 KB
create-tables-a.sql application/octet-stream 1.7 KB
bench_bitmapset_ubuntu.txt text/plain 1.6 KB
bench_bitmapset_ubuntu.ods application/vnd.oasis.opendocument.spreadsheet 22.4 KB
bench_bitmapset_windows.ods application/vnd.oasis.opendocument.spreadsheet 22.1 KB
create-tables-b.sql application/octet-stream 915 bytes
query-a.sql application/octet-stream 307 bytes
pgbench_prepared1.txt text/plain 2.9 KB
query-b.sql application/octet-stream 491 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2023-06-25 13:32:08 Re: Do we want a hashset type?
Previous Message Tatsuo Ishii 2023-06-25 12:05:09 Row pattern recognition