pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fabien COELHO <coelho@cri.ensmp.fr>
To: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Aleksander Alekseev <aleksander@timescale.com>
Cc: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Subject: Re: rand48 replacement
Date: Fri, 2 Jul 2021 23:51:42 +0200 (CEST)
Message-ID: <alpine.DEB.2.22.394.2107022340250.2359988@pseudo> (raw)
In-Reply-To: <CAEZATCVpnOjrwU=4712OPjNDqV2sVkkK7XHDiR-nzYDL8N6z=Q@mail.gmail.com>
References: <alpine.DEB.2.22.394.2105241211230.165418@pseudo>
	<43a6e30b-542f-671a-e7bb-b7f78cf90e8c@enterprisedb.com>
	<alpine.DEB.2.22.394.2105241310350.165418@pseudo>
	<CAJ7c6TM2qJdtehyLA79gFtZ+h7jwRrksK4ZAW7boxgQJqQkRAw@mail.gmail.com>
	<alpine.DEB.2.22.394.2105241509200.165418@pseudo>
	<699567.1625156441@sss.pgh.pa.us>
	<alpine.DEB.2.22.394.2107011842240.2143494@pseudo>
	<746421.1625164869@sss.pgh.pa.us>
	<CAEZATCXvzDSNhH2uRMUt5K_vmMBDrvo+D7Sn66--1Z_ELz==5Q@mail.gmail.com>
	<alpine.DEB.2.22.394.2107012212500.2248546@pseudo>
	<CAEZATCVpnOjrwU=4712OPjNDqV2sVkkK7XHDiR-nzYDL8N6z=Q@mail.gmail.com>


Hello Dean,

> It may be true that the bias is of the same magnitude as FP multiply, 
> but it is not of the same nature. With FP multiply, the 
> more-likely-to-be-chosen values are more-or-less evenly distributed 
> across the range, whereas modulo concentrates them all at one end, 
> making it more likely to bias test results.

Yes, that is true.

> It's worth paying attention to how other languages/libraries implement
> this, and basically no one chooses the modulo method, which ought to
> raise alarm bells. Of the biased methods, it has the worst kind of
> bias and the worst performance.

Hmmm. That is not exactly how I interpreted the figures in the blog.

> If a biased method is OK, then the biased integer multiply method
> seems to be the clear winner. This requires the high part of a
> 64x64-bit product, which is trivial if 128-bit integers are available,
> but would need a little more work otherwise. There's some code in
> common/d2s that might be suitable.

And yes, modulo is expensive. If we allow 128 bits integers operations, I 
would not choose this RNPG in the first place, I'd take PCG with a 128 bits state.
That does not change the discussion about bias, though.

> Most other implementations tend to use an unbiased method though, and I 
> think it's worth doing the same. It might be a bit slower, or even 
> faster depending on implementation and platform, but in the context of 
> the DB as a whole, I don't think a few extra cycles matters either way.

Ok ok ok, I surrender!

> The method recommended at the very end of that blog seems to be pretty 
> good all round, but any of the other commonly used unbiased methods 
> would probably be OK too.

That does not address my other issues with the proposed methods, in 
particular the fact that the generated sequence is less deterministic, but 
I think I have a simple way around that. I'm hesitating to skip to the the 
bitmask method, and give up performance uniformity. I'll try to come up 
with something over the week-end, and also address Tom's comments in 
passing.

-- 
Fabien.





view thread (59+ messages)  latest in thread

Message-ID: <alpine.DEB.2.22.394.2107022340250.2359988@pseudo>
Permalink:  ../alpine.DEB.2.22.394.2107022340250.2359988@pseudo/
Also on:    postgresql.org/message-id/alpine.DEB.2.22.394.2107022340250.2359988@pseudo

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: coelho@cri.ensmp.fr, dean.a.rasheed@gmail.com, tgl@sss.pgh.pa.us, aleksander@timescale.com
  Subject: Re: rand48 replacement
  In-Reply-To: <alpine.DEB.2.22.394.2107022340250.2359988@pseudo>
  References: <alpine.DEB.2.22.394.2105241211230.165418@pseudo> <43a6e30b-542f-671a-e7bb-b7f78cf90e8c@enterprisedb.com> <alpine.DEB.2.22.394.2105241310350.165418@pseudo> <CAJ7c6TM2qJdtehyLA79gFtZ+h7jwRrksK4ZAW7boxgQJqQkRAw@mail.gmail.com> <alpine.DEB.2.22.394.2105241509200.165418@pseudo> <699567.1625156441@sss.pgh.pa.us> <alpine.DEB.2.22.394.2107011842240.2143494@pseudo> <746421.1625164869@sss.pgh.pa.us> <CAEZATCXvzDSNhH2uRMUt5K_vmMBDrvo+D7Sn66--1Z_ELz==5Q@mail.gmail.com> <alpine.DEB.2.22.394.2107012212500.2248546@pseudo> <CAEZATCVpnOjrwU=4712OPjNDqV2sVkkK7XHDiR-nzYDL8N6z=Q@mail.gmail.com> <alpine.DEB.2.22.394.2107022340250.2359988@pseudo>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox