Use 31 instead of 15-bit int for temp dir names

unit_tests creates two temporary directories for each test process. When
run with --test-launcher-batch-limit=1 this means about 21,800
directories, 10,900 of each naming pattern.

This is a problem because CreateTemporaryDirInDir uses a 15-bit random
number to generate directory names. After we have generated just 214
names there is a greater than 50% probability of a collision and after
10,900 names there will have been thousands of collisions. These
collisions are handled but they harm startup performance (especially
when running with --test-launcher-batch-limit=1) and if we add enough
tests or if directory cleanup isn't perfect then the slowdown can go

Using a GUID would avoid all collisions but causes failures because
a GUID is 36 characters - 31 longer - and we sometimes have nested
temp directories. The extra 62 characters hits path length limits. Using
31-bit ints means the dir names are only 5 characters longer.

Bug: 955038, 956723
Change-Id: Id8d921eba0a59a3e4031470ccb5ae5368f6144db
Commit-Queue: Robert Liao <>
Reviewed-by: Robert Liao <>
Cr-Commit-Position: refs/heads/master@{#654287}
1 file changed