Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Issue 140773006: Improve base::RandBytes() performance by 1.75x-2.10x on POSIX. (Closed)

Created:
6 years, 11 months ago by DaleCurtis
Modified:
6 years, 11 months ago
CC:
chromium-reviews, erikwright+watch_chromium.org
Visibility:
Public.

Description

Improve base::RandBytes() performance by 1.75x-2.10x on POSIX. No real changes, just avoids doling out Uint64 sized chunks by using the underlying method to hand out correctly sized blocks. Windows is the only platform which doesn't have a byte stream based generator, so I've moved the generic RandBytes() method there and added native methods for other platforms which reuse each platforms internal generator. Performance measured by the new benchmark test over 5 runs, each representing 10 generations of 1mb of random data: Linux x64: Original: 1199625.4 Modified: 686480.2 Improvement: 1.75x On OSX (10.9.1): Original: 1532669.8 Modified: 734808.0 Improvement: 2.10x BUG=none TEST=new benchmark unittest. Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=246486

Patch Set 1 #

Patch Set 2 : Fix NaCl uint32 boundary. #

Patch Set 3 : Cleanup style. Const. #

Total comments: 2

Patch Set 4 : Comments. Simplify. #

Patch Set 5 : Simplify NaCl. #

Total comments: 16

Patch Set 6 : Comments. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+55 lines, -30 lines) Patch
M base/rand_util.cc View 1 chunk +0 lines, -10 lines 0 comments Download
M base/rand_util_nacl.cc View 1 2 3 4 5 2 chunks +13 lines, -9 lines 0 comments Download
M base/rand_util_posix.cc View 1 2 3 4 5 2 chunks +10 lines, -11 lines 0 comments Download
M base/rand_util_unittest.cc View 1 2 3 4 5 2 chunks +22 lines, -0 lines 0 comments Download
M base/rand_util_win.cc View 1 2 3 4 5 1 chunk +10 lines, -0 lines 0 comments Download

Messages

Total messages: 22 (0 generated)
DaleCurtis
Could be implemented on Windows by using the RtlGenRandom() method, but that seems to require ...
6 years, 11 months ago (2014-01-17 23:27:12 UTC) #1
DaleCurtis
Over to thakis@ since ajwong@ is OOO for a while.
6 years, 11 months ago (2014-01-17 23:31:24 UTC) #2
DaleCurtis
+rsleevi since RandBytes() passes through to crypto/random.{h,cc}
6 years, 11 months ago (2014-01-17 23:45:41 UTC) #3
Ryan Sleevi
rand_s is implemented by using RtlGenRandom in MSVCRT, so you already have the dependency on ...
6 years, 11 months ago (2014-01-18 00:01:15 UTC) #4
DaleCurtis
Using RtlGenRandom directly yielded a massive 44x improvement for larger buffer sizes! That CL is ...
6 years, 11 months ago (2014-01-18 00:25:08 UTC) #5
DaleCurtis
jschuh, thakis: Ping?
6 years, 11 months ago (2014-01-22 20:59:43 UTC) #6
Nico
lgtm Nice! https://codereview.chromium.org/140773006/diff/100001/base/rand_util_posix.cc File base/rand_util_posix.cc (right): https://codereview.chromium.org/140773006/diff/100001/base/rand_util_posix.cc#newcode46 base/rand_util_posix.cc:46: ReadFromFD(urandom_fd, reinterpret_cast<char*>(&number), sizeof(number))); nit: I liked the ...
6 years, 11 months ago (2014-01-22 21:03:29 UTC) #7
Nico
(And keeping the windows cl separate is preferable, I think.) On Wed, Jan 22, 2014 ...
6 years, 11 months ago (2014-01-22 21:04:12 UTC) #8
DaleCurtis
https://codereview.chromium.org/140773006/diff/100001/base/rand_util_posix.cc File base/rand_util_posix.cc (right): https://codereview.chromium.org/140773006/diff/100001/base/rand_util_posix.cc#newcode46 base/rand_util_posix.cc:46: ReadFromFD(urandom_fd, reinterpret_cast<char*>(&number), sizeof(number))); On 2014/01/22 21:03:30, Nico wrote: > ...
6 years, 11 months ago (2014-01-22 21:12:17 UTC) #9
jschuh
D'oh, sorry. This was on my list of things to fix, so thanks for taking ...
6 years, 11 months ago (2014-01-22 21:15:20 UTC) #10
DaleCurtis
Looks like the NaCl interface is actually size_t, so the chunking code can be removed: ...
6 years, 11 months ago (2014-01-22 21:38:19 UTC) #11
bradn
+wtc lgtm on the nacl part. I had a question on windows. I've adde wtc ...
6 years, 11 months ago (2014-01-22 21:56:12 UTC) #12
DaleCurtis
Lets move the Windows discussion to this CL: https://codereview.chromium.org/141753009/ I've added you and wtc there.
6 years, 11 months ago (2014-01-22 21:59:00 UTC) #13
DaleCurtis
CQ'ing this one. Thanks for the reviews everyone.
6 years, 11 months ago (2014-01-22 22:03:13 UTC) #14
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/dalecurtis@chromium.org/140773006/210001
6 years, 11 months ago (2014-01-22 22:03:53 UTC) #15
wtc
Patch set 5 LGTM. Please fix the coding style and comment nits before you commit ...
6 years, 11 months ago (2014-01-22 22:29:08 UTC) #16
DaleCurtis
https://codereview.chromium.org/140773006/diff/210001/base/rand_util_nacl.cc File base/rand_util_nacl.cc (right): https://codereview.chromium.org/140773006/diff/210001/base/rand_util_nacl.cc#newcode46 base/rand_util_nacl.cc:46: // NOTE: This function must be cryptographically secure. http://crbug.com/140076 ...
6 years, 11 months ago (2014-01-22 22:36:26 UTC) #17
wtc
https://codereview.chromium.org/140773006/diff/210001/base/rand_util_nacl.cc File base/rand_util_nacl.cc (right): https://codereview.chromium.org/140773006/diff/210001/base/rand_util_nacl.cc#newcode46 base/rand_util_nacl.cc:46: // NOTE: This function must be cryptographically secure. http://crbug.com/140076 ...
6 years, 11 months ago (2014-01-22 22:47:11 UTC) #18
DaleCurtis
https://codereview.chromium.org/140773006/diff/210001/base/rand_util_nacl.cc File base/rand_util_nacl.cc (right): https://codereview.chromium.org/140773006/diff/210001/base/rand_util_nacl.cc#newcode46 base/rand_util_nacl.cc:46: // NOTE: This function must be cryptographically secure. http://crbug.com/140076 ...
6 years, 11 months ago (2014-01-22 22:54:14 UTC) #19
wtc
Patch set 6 LGTM. Thanks.
6 years, 11 months ago (2014-01-22 23:01:43 UTC) #20
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/dalecurtis@chromium.org/140773006/470001
6 years, 11 months ago (2014-01-22 23:04:30 UTC) #21
commit-bot: I haz the power
6 years, 11 months ago (2014-01-23 02:14:30 UTC) #22
Message was sent while issue was closed.
Change committed as 246486

Powered by Google App Engine
This is Rietveld 408576698