develooper Front page | perl.perl5.porters | Postings from July 2020

Re: PERL_PERTURB_KEYS=2

Thread Previous | Thread Next
From:
demerphq
Date:
July 28, 2020 12:48
Subject:
Re: PERL_PERTURB_KEYS=2
Message ID:
CANgJU+Wx6m9mE-DY=RDqak+-NKX+kbUXsJZWpF_qeFBaXz1Yow@mail.gmail.com
On Mon, 27 Jul 2020 at 15:57, <hv@crypt.org> wrote:
>
> I have an application that I believe is otherwise deterministic, but had
> a heisenbug caused by an unintentional dependency on hash ordering.
>
> Before managing to find the bug by other means, I tried unsuccessully
> to create a reproducible testcase by experimentally setting PERL_HASH_SEED
> to $h > 0, and PERL_PERTURB_KEYS to $k in (0, 1 (default), 2).
>
> I found that with $k=1 the application failed randomly for each $h;
> with $k=0 it consistently succeeded for each $h; and with $k=2 it
> again failed randomly for each $h. That last ("DETERMINISTIC") feels
> like a bug.
>
> I tried unsuccessfully to reproduce the issue with a simple test:
>   $ENV{PERL_PERTURB_KEYS} = 2;

>   for my $h (1 .. 10) {
>     for (1 .. 3) {
>       local $ENV{PERL_HASH_SEED} = $h;
>       print "$h: ";
>       system(q{perl}, q{-e}, q{
>         %x = map +($_ => 1), ("a".."z");
>         print join("", keys %x), "\n";
>       })
>     }
>   }
> .. but saw no non-deterministic behaviour there (and in fact $h does
> not seem to cause any variation in results either).

I do not really understand the question. What I see, below, is what I
expect, 10 triplets of the same thing.

$ perl t.pl
1: ynxpwfzakiceqbjlhutvsodgmr
1: ynxpwfzakiceqbjlhutvsodgmr
1: ynxpwfzakiceqbjlhutvsodgmr
2: xhipulwjymensrbvkotfdzcagq
2: xhipulwjymensrbvkotfdzcagq
2: xhipulwjymensrbvkotfdzcagq
3: koxvyjzlhitdanpfqcgurswebm
3: koxvyjzlhitdanpfqcgurswebm
3: koxvyjzlhitdanpfqcgurswebm
4: esjbtnlaifpxgryvmowcqukdhz
4: esjbtnlaifpxgryvmowcqukdhz
4: esjbtnlaifpxgryvmowcqukdhz
5: ksdveiytjquhrozfxmbcwglnpa
5: ksdveiytjquhrozfxmbcwglnpa
5: ksdveiytjquhrozfxmbcwglnpa
6: hasownfcejpymxrdukvzbgtliq
6: hasownfcejpymxrdukvzbgtliq
6: hasownfcejpymxrdukvzbgtliq
7: yaodewbtcxqhjgmipukvlsnrfz
7: yaodewbtcxqhjgmipukvlsnrfz
7: yaodewbtcxqhjgmipukvlsnrfz
8: ycbktxleufsqhzamjovnipdgwr
8: ycbktxleufsqhzamjovnipdgwr
8: ycbktxleufsqhzamjovnipdgwr
9: idsgnalxtqobrhmcuypjfzvwke
9: idsgnalxtqobrhmcuypjfzvwke
9: idsgnalxtqobrhmcuypjfzvwke
10: ynxpwfzakiceqbjlhutvsodgmr
10: ynxpwfzakiceqbjlhutvsodgmr
10: ynxpwfzakiceqbjlhutvsodgmr

and if I run it twice I see the same thing

$ perl t.pl > t.out1
$ perl t.pl > t.out2
$ diff t.out1 t.out2
$

You should see the same. What do you see instead and what do you expect to see?

BTW, PERL_PERTURB_KEYS = 2 does not stop the peturbing, it makes the
perturbing deterministic, when PERL_PERTURB_KEYS = 1 it mixes in data
which can vary from run to run. PERL_PERTURB_KEYS stops the perturbing
entirely.

Also PERL_PERTURB_KEYS is orthogonal to PERL_HASH_SEED. And yes,
setting the seed changes the order, which is why there are 10 sets of
the same order.

I think what you want is to do PERL_HASH_SEED=0 which is magic, and
sets PERL_PERTURB_KEYS=0 and sets the seed to a standard default, so
from the point of view of the hash engine it is totally deterministic.

Yves




-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About