[PATCH 00 of 24] PYTHONHASHSEED=random

Mads Kiilerich mads at kiilerich.com
Mon Dec 17 20:34:37 CST 2012


Bryan O'Sullivan wrote, On 12/17/2012 10:06 PM:
> There are just a few patches where you changed core code that never 
> produces user-visible output, instead of fixing tests to use sort 
> instead of cat. If you could change the tests instead, that would be 
> better.

That must be patch 2-4 which sorts the content of the repo files 
"requires", "branchheads" and "bisect.state".

Yes, that could probably work too.

But
- These files are in a readable format. A random ordering makes them 
less readable - sorting the entries supports the existing idea of making 
the files readable.
- Tools that use random ordering often turns out to be annoying. (For 
instance when diffing/tracking Firefox configuration files and various 
wysiwyg text document formats...) Using a well-defined ordering gives a 
much more trustworthy impression.

I think it would be better to just use the representation that is most 
convenient for our own use instead of adding workarounds.

Any other opinions or arguments? (Even though this is such a minor issue 
that it hardly is worth spending time on.)



A general comment to .iteritems() or not:

It is obvious to use .iteritems() in "for x in d.iteritems()" to yield 
the items lazily, but the advantage becomes less obvious when the a 
sorter() is added. Then we could just as well focus in readability and 
making the code short.

Some timeit benchmarking showed that:

sorted(d.items()) is faster for few items (because it avoids the 
overhead of generating an iterator?).

sorted(d.iteritems()) is faster for something like more than 1000 items 
(because it avoids creating an extra list and adjusting reference counts 
several times)?.

(and similarly, sorted(d.keys()) is often faster than sorted(d).)

Conclusion: there is no conclusion.

It would in most places for all practical purposes be more efficient to 
use .items() ... but we could also combine consistency and scalability 
and use .iteritems() "everywhere". That is what I now in general would 
aim at when I get to pushing this series.

/Mads


More information about the Mercurial-devel mailing list