Files
Zygmunt Krynicki bf067f57db osutil/mount: optimize flagOptSearch some more
Ideas employed
 - reorder fields so that mask is before the string
 - use POPCNT to estimate allocation size
 - allocate late on demand
 - pre-compute mask of known flags
 - bail out when known flags are handled

This yields improvements in most of the benchmarks:

Before:

    BenchmarkUnmountFlagsToOptsAllMissing-4   	200000000	         6.07 ns/op
    BenchmarkUnmountFlagsToOptsMixed-4        	50000000	        36.8 ns/op
    BenchmarkUnmountFlagsToOptsAllPresent-4   	10000000	       158 ns/op
    BenchmarkMountFlagsToOptsAllMissing-4     	200000000	         9.93 ns/op
    BenchmarkMountFlagsToOptsAllPresent-4     	10000000	       230 ns/op
    BenchmarkMountFlagsToOptsMixed-4          	30000000	        41.4 ns/op
    BenchmarkMountFlagsToOptsTypical-4        	30000000	        41.8 ns/op

After:

    BenchmarkUnmountFlagsToOptsAllMissing-4   	500000000	         3.41 ns/op
    BenchmarkUnmountFlagsToOptsMixed-4        	30000000	        54.3 ns/op
    BenchmarkUnmountFlagsToOptsAllPresent-4   	20000000	        63.8 ns/op
    BenchmarkMountFlagsToOptsAllMissing-4     	500000000	         3.71 ns/op
    BenchmarkMountFlagsToOptsAllPresent-4     	20000000	        83.6 ns/op
    BenchmarkMountFlagsToOptsMixed-4          	20000000	        51.5 ns/op
    BenchmarkMountFlagsToOptsTypical-4        	50000000	        33.2 ns/op

I've also added a "typical" benchmark with one known flag only.

Signed-off-by: Zygmunt Krynicki <me@zygoon.pl>
2019-11-27 09:45:47 +01:00
..