patrickfav/bcrypt

Add ProGuard optimized version

patrickfav opened this issue · 2 comments

ProGuard has certain optimization rules which may increase the performance of the hash.

It seems that ProGuard can't do too many optimizations:

[INFO] --- proguard-maven-plugin:2.0.14:proguard (default) @ bcrypt-core ---
[INFO] execute ProGuard [-injars, 'C:\Users\patri\workspaces\bcrypt\bcrypt-core\target\bcrypt-core-0.4.0.jar'(!META-INF/maven/**), -libraryjars, 'C:\Users\patri\.m2\repository\at\favre\lib\bytes\0.4.6\bytes-0.4.6.jar', -outjars, 'C:\Users\patri\workspaces\bcrypt\bcrypt-core\target\bcrypt-core-0.4.0-optimized.jar', -dontobfuscate, -libraryjars, 'C:\Program Files\Java\jdk1.8.0_172\jre/lib/rt.jar', -printmapping, 'C:\Users\patri\workspaces\bcrypt\bcrypt-core\target\proguard_map.txt', -printseeds, 'C:\Users\patri\workspaces\bcrypt\bcrypt-core\target\proguard_seed.txt', -include C:\Users\patri\workspaces\bcrypt\bcrypt-core/proguard-rules.pro]
[INFO] proguard jar: C:\Users\patri\.m2\repository\net\sf\proguard\proguard-base\6.0.3\proguard-base-6.0.3.jar
 [proguard] ProGuard, version 6.0.3
 [proguard] Reading input...
 [proguard] Reading program jar [C:\Users\patri\workspaces\bcrypt\bcrypt-core\target\bcrypt-core-0.4.0.jar] (filtered)
 [proguard] Reading library jar [C:\Users\patri\.m2\repository\at\favre\lib\bytes\0.4.6\bytes-0.4.6.jar]
 [proguard] Reading library jar [C:\Program Files\Java\jdk1.8.0_172\jre\lib\rt.jar]
 [proguard] Initializing...
 [proguard] Ignoring unused library classes...
 [proguard]   Original number of library classes: 19856
 [proguard]   Final number of library classes:    122
 [proguard] Printing kept classes, fields, and methods...
 [proguard] Inlining subroutines...
 [proguard] Shrinking...
 [proguard] Removing unused program classes and class elements...
 [proguard]   Original number of program classes: 22
 [proguard]   Final number of program classes:    22
 [proguard] Optimizing (pass 1/3)...
 [proguard]   Number of finalized classes:                   2
 [proguard]   Number of unboxed enum classes:                0
 [proguard]   Number of vertically merged classes:           0   (disabled)
 [proguard]   Number of horizontally merged classes:         0   (disabled)
 [proguard]   Number of merged wrapper classes:              0   (disabled)
 [proguard]   Number of removed write-only fields:           0   (disabled)
 [proguard]   Number of privatized fields:                   0   (disabled)
 [proguard]   Number of inlined constant fields:             0   (disabled)
 [proguard]   Number of privatized methods:                  1
 [proguard]   Number of staticized methods:                  5
 [proguard]   Number of finalized methods:                   32
 [proguard]   Number of desynchronized methods:              0
 [proguard]   Number of simplified method signatures:        0
 [proguard]   Number of removed method parameters:           0
 [proguard]   Number of inlined constant parameters:         1
 [proguard]   Number of inlined constant return values:      0
 [proguard]   Number of inlined short method calls:          0
 [proguard]   Number of inlined unique method calls:         5
 [proguard]   Number of inlined tail recursion calls:        0
 [proguard]   Number of merged code blocks:                  0
 [proguard]   Number of variable peephole optimizations:     19
 [proguard]   Number of arithmetic peephole optimizations:   0   (disabled)
 [proguard]   Number of cast peephole optimizations:         0   (disabled)
 [proguard]   Number of field peephole optimizations:        1
 [proguard]   Number of branch peephole optimizations:       4
 [proguard]   Number of object peephole optimizations:       0
 [proguard]   Number of string peephole optimizations:       12
 [proguard]   Number of math peephole optimizations:         0
 [proguard]   Number of simplified instructions:             3
 [proguard]   Number of removed instructions:                10
 [proguard]   Number of removed local variables:             7
 [proguard]   Number of removed exception blocks:            4
 [proguard]   Number of optimized local variable frames:     16
 [proguard] Shrinking...
 [proguard] Removing unused program classes and class elements...
 [proguard]   Original number of program classes: 22
 [proguard]   Final number of program classes:    20
 [proguard] Optimizing (pass 2/3)...
 [proguard]   Number of finalized classes:                   0
 [proguard]   Number of unboxed enum classes:                0
 [proguard]   Number of vertically merged classes:           0   (disabled)
 [proguard]   Number of horizontally merged classes:         0   (disabled)
 [proguard]   Number of merged wrapper classes:              0   (disabled)
 [proguard]   Number of removed write-only fields:           0   (disabled)
 [proguard]   Number of privatized fields:                   0   (disabled)
 [proguard]   Number of inlined constant fields:             0   (disabled)
 [proguard]   Number of privatized methods:                  0
 [proguard]   Number of staticized methods:                  2
 [proguard]   Number of finalized methods:                   0
 [proguard]   Number of desynchronized methods:              0
 [proguard]   Number of simplified method signatures:        3
 [proguard]   Number of removed method parameters:           3
 [proguard]   Number of inlined constant parameters:         2
 [proguard]   Number of inlined constant return values:      0
 [proguard]   Number of inlined short method calls:          0
 [proguard]   Number of inlined unique method calls:         0
 [proguard]   Number of inlined tail recursion calls:        0
 [proguard]   Number of merged code blocks:                  0
 [proguard]   Number of variable peephole optimizations:     1
 [proguard]   Number of arithmetic peephole optimizations:   0   (disabled)
 [proguard]   Number of cast peephole optimizations:         0   (disabled)
 [proguard]   Number of field peephole optimizations:        0
 [proguard]   Number of branch peephole optimizations:       1
 [proguard]   Number of object peephole optimizations:       0
 [proguard]   Number of string peephole optimizations:       2
 [proguard]   Number of math peephole optimizations:         0
 [proguard]   Number of simplified instructions:             1
 [proguard]   Number of removed instructions:                29
 [proguard]   Number of removed local variables:             2
 [proguard]   Number of removed exception blocks:            0
 [proguard]   Number of optimized local variable frames:     1
 [proguard] Shrinking...
 [proguard] Removing unused program classes and class elements...
 [proguard]   Original number of program classes: 20
 [proguard]   Final number of program classes:    20
 [proguard] Optimizing (pass 3/3)...
 [proguard]   Number of finalized classes:                   0
 [proguard]   Number of unboxed enum classes:                0
 [proguard]   Number of vertically merged classes:           0   (disabled)
 [proguard]   Number of horizontally merged classes:         0   (disabled)
 [proguard]   Number of merged wrapper classes:              0   (disabled)
 [proguard]   Number of removed write-only fields:           0   (disabled)
 [proguard]   Number of privatized fields:                   0   (disabled)
 [proguard]   Number of inlined constant fields:             0   (disabled)
 [proguard]   Number of privatized methods:                  0
 [proguard]   Number of staticized methods:                  1
 [proguard]   Number of finalized methods:                   0
 [proguard]   Number of desynchronized methods:              0
 [proguard]   Number of simplified method signatures:        1
 [proguard]   Number of removed method parameters:           2
 [proguard]   Number of inlined constant parameters:         2
 [proguard]   Number of inlined constant return values:      0
 [proguard]   Number of inlined short method calls:          0
 [proguard]   Number of inlined unique method calls:         0
 [proguard]   Number of inlined tail recursion calls:        0
 [proguard]   Number of merged code blocks:                  0
 [proguard]   Number of variable peephole optimizations:     1
 [proguard]   Number of arithmetic peephole optimizations:   0   (disabled)
 [proguard]   Number of cast peephole optimizations:         0   (disabled)
 [proguard]   Number of field peephole optimizations:        0
 [proguard]   Number of branch peephole optimizations:       0
 [proguard]   Number of object peephole optimizations:       0
 [proguard]   Number of string peephole optimizations:       0
 [proguard]   Number of math peephole optimizations:         0
 [proguard]   Number of simplified instructions:             1
 [proguard]   Number of removed instructions:                7
 [proguard]   Number of removed local variables:             1
 [proguard]   Number of removed exception blocks:            0
 [proguard]   Number of optimized local variable frames:     0
 [proguard] Shrinking...
 [proguard] Removing unused program classes and class elements...
 [proguard]   Original number of program classes: 20
 [proguard]   Final number of program classes:    20
 [proguard] Preverifying...
 [proguard] Writing output...
 [proguard] Preparing output jar [C:\Users\patri\workspaces\bcrypt\bcrypt-core\target\bcrypt-core-0.4.0-optimized.jar]
 [proguard]   Copying resources from program jar [C:\Users\patri\workspaces\bcrypt\bcrypt-core\target\bcrypt-core-0.4.0.jar] (filtered)

Using JMH micro benchmark to compare there is no noticeable difference in performance between the proguard and non-proguard version:

Proguard

Benchmark                             (cost)  Mode  Cnt    Score   Error  Units
BcryptBenchmark.benchmarkFavreBcrypt      10  avgt    3   54,151 ± 1,459  ms/op
BcryptBenchmark.benchmarkFavreBcrypt      12  avgt    3  215,901 ± 1,058  ms/op

Proguard Bcrypt + Bytes

Benchmark                             (cost)  Mode  Cnt    Score   Error  Units
BcryptBenchmark.benchmarkFavreBcrypt      10  avgt    3   54,119 ± 0,844  ms/op
BcryptBenchmark.benchmarkFavreBcrypt      12  avgt    3  215,874 ± 1,824  ms/op

Non-Proguard

Benchmark                             (cost)  Mode  Cnt    Score   Error  Units
BcryptBenchmark.benchmarkFavreBcrypt      10  avgt    3   54,009 ± 0,933  ms/op
BcryptBenchmark.benchmarkFavreBcrypt      12  avgt    3  215,862 ± 1,141  ms/op