dogecoin / dogecoin

very currency
MIT License
14.4k stars 2.8k forks source link

1.15.0 dev improve random upstream cherry picks #3487

Open chromatic opened 1 month ago

chromatic commented 1 month ago

This is a work in progress to cherry-pick some upstream randomization improvements (see #3229 for context).

patricklodder commented 1 month ago

I benched this on both an x86_64 Intel I7 and an arm64 Apple M1. Results:

On i7-970

Current FastRandomContext (at 8d4e0bd085)

#Benchmark,count,min,max,average,min_cycles,max_cycles,average_cycles
FastRandom_1bit,640,0.001588508486748,0.001606859266758,0.001596468687057,5144478,5203874,5170219
FastRandom_32bit,640,0.001587942242622,0.001599781215191,0.001593051850796,5142448,5180947,5159149

New FastRandomContext (at 9c33a274e4)

#Benchmark,count,min,max,average,min_cycles,max_cycles,average_cycles
FastRandom_1bit,576,0.001762509346008,0.001951079815626,0.001785520878103,5707967,6318597,5782466
FastRandom_32bit,88,0.011499375104904,0.011546224355698,0.011518229137767,37241032,37393131,37302139

On Apple M1

Current FastRandomContext

#Benchmark,count,min,max,average,min_cycles,max_cycles,average_cycles
FastRandom_1bit,416,0.002500720322132,0.002539746463299,0.002514704488791,0,0,0
FastRandom_32bit,416,0.002498909831047,0.002532906830311,0.002507672860072,0,0,0

New FastRandomContext

#Benchmark,count,min,max,average,min_cycles,max_cycles,average_cycles
FastRandom_1bit,1280,0.000798149034381,0.000805476680398,0.000799535214901,0,0,0
FastRandom_32bit,160,0.006616741418839,0.006684437394142,0.006653493642807,0,0,0
patricklodder commented 1 month ago

I picked the following on top for a ~10% performance increase on the 32-bit FastRandomContext call:

There are probably more enhancements that are worth picking, but this (on the same i7-970 as above) at least consistently gave me:

#Benchmark,count,min,max,average,min_cycles,max_cycles,average_cycles
FastRandom_1bit,576,0.001733902841806,0.002175435423851,0.001750805725654,5615303,7045181,5670042
FastRandom_32bit,96,0.010480642318726,0.010773122310638,0.010528010626634,33942116,34889024,34095342
xanimo commented 1 month ago

Everything is looking good so far. Tested successfully on x86_64-pc-linux-gnu jammy.

FastRandom_1bit,768,0.001310061663389,0.001355305314064,0.001322269439697,3270081,3383005,3300558
FastRandom_32bit,120,0.008004248142242,0.010467499494553,0.008429358402888,19979437,26128340,21040796
chromatic commented 1 month ago

I can't seem to reproduce a clean cherry-pick like you mention, @patricklodder . Did you reproduce from 9c33a2 or is there another commit? I get conflicts around noexcept for FastRandomContext::FastRandomContext().

xanimo commented 1 month ago

Everything is looking good so far. Tested successfully on x86_64-pc-linux-gnu jammy.

FastRandom_1bit,768,0.001310061663389,0.001355305314064,0.001322269439697,3270081,3383005,3300558
FastRandom_32bit,120,0.008004248142242,0.010467499494553,0.008429358402888,19979437,26128340,21040796

@chromatic This one is a bit further down the road but in comparison here are my results with those cherry-picks @patricklodder mentioned:

FastRandom_1bit,832,0.001286000013351,0.001319061964750,0.001300879969047,3209897,3292369,3247008
FastRandom_32bit,128,0.007689073681831,0.008537530899048,0.008067343384027,19191829,21310164,20136173
xanimo commented 1 month ago

Running on a i5-10300H*