bobg / modver

MIT License
19 stars 6 forks source link

Optimizations based on commutativity of identical #27

Closed bobg closed 3 days ago

bobg commented 5 months ago

This PR adds a couple of optimizations based on the commutativity of comparer.identical.

(Specifically, if type pair a,b is not found in the cache, look for b,a too.)

Also switch from pkg/errors to bobg/errors, and refactor the main test to add a benchmark. Benchstat output:

goos: darwin
goarch: arm64
pkg: github.com/bobg/modver/v2
cpu: Apple M3
                                      │   BENCH.old    │               BENCH.new                │
                                      │     sec/op     │     sec/op      vs base                │
Compare/major/addfntypeparam-8          0.05971n ±  5%   0.04383n ±  2%  -26.58% (p=0.000 n=10)
Compare/major/addmethod-8               0.06058n ±  4%   0.04741n ± 14%  -21.75% (p=0.001 n=10)
Compare/major/addparam-8                0.05894n ± 10%   0.04494n ±  2%  -23.76% (p=0.000 n=10)
Compare/major/addresult-8               0.06449n ±  1%   0.04691n ± 68%  -27.26% (p=0.029 n=10)
Compare/major/addtypeparam-8            0.06391n ±  1%   0.07100n ± 34%        ~ (p=0.529 n=10)
Compare/major/alltosomecomparable-8     0.05811n ±  1%   0.04671n ± 75%  -19.62% (p=0.022 n=10)
Compare/major/anytocomparable-8         0.05825n ±  9%   0.04625n ±  3%  -20.60% (p=0.001 n=10)
Compare/major/anytosomecomparable-8     0.05527n ± 11%   0.04541n ±  1%  -17.84% (p=0.000 n=10)
Compare/major/changetype-8              0.05502n ±  2%   0.04553n ±  4%  -17.23% (p=0.001 n=10)
Compare/major/charraylen-8              0.05425n ±  1%   0.04477n ±  2%  -17.49% (p=0.000 n=10)
Compare/major/charraytype-8             0.05759n ±  9%   0.04655n ±  3%  -19.17% (p=0.000 n=10)
Compare/major/chchandir-8               0.05372n ±  2%   0.04580n ± 14%  -14.74% (p=0.002 n=10)
Compare/major/chconstant-8              0.05539n ± 18%   0.04536n ±  4%  -18.12% (p=0.000 n=10)
Compare/major/chfield-8                 0.06355n ±  6%   0.04560n ±  2%  -28.24% (p=0.000 n=10)
Compare/major/chintf-8                  0.05884n ±  2%   0.04738n ± 15%  -19.49% (p=0.002 n=10)
Compare/major/chmodname-8               0.05648n ±  3%   0.04578n ±  1%  -18.95% (p=0.000 n=10)
Compare/major/chparam-8                 0.05686n ±  2%   0.04637n ±  1%  -18.44% (p=0.001 n=10)
Compare/major/chtag-8                   0.05599n ± 12%   0.04658n ± 11%  -16.81% (p=0.000 n=10)
Compare/major/diffunions-8              0.06110n ±  8%   0.04661n ±  2%  -23.73% (p=0.000 n=10)
Compare/major/fromcomparable-8          0.05922n ± 12%   0.04664n ±  5%  -21.24% (p=0.000 n=10)
Compare/major/fromconstraint-8          0.06138n ±  4%   0.04688n ±  1%  -23.61% (p=0.000 n=10)
Compare/major/hashsplit-8                0.1671n ±  4%    0.1398n ±  2%  -16.34% (p=0.000 n=10)
Compare/major/pointer-8                 0.06443n ± 15%   0.04705n ±  1%  -26.99% (p=0.001 n=10)
Compare/major/remove-8                  0.06400n ±  6%   0.04655n ±  4%  -27.27% (p=0.000 n=10)
Compare/major/rmfield-8                 0.05829n ±  4%   0.04728n ± 12%  -18.89% (p=0.000 n=10)
Compare/major/rmmethod-8                0.06038n ± 30%   0.04792n ±  3%  -20.63% (p=0.000 n=10)
Compare/major/rmpackage-8               0.06212n ±  8%   0.04888n ±  2%  -21.32% (p=0.000 n=10)
Compare/major/rmtag-8                   0.05880n ± 10%   0.04620n ±  1%  -21.41% (p=0.000 n=10)
Compare/major/rmunion-8                 0.05947n ± 10%   0.04625n ± 11%  -22.23% (p=0.000 n=10)
Compare/major/tightenconstraint1-8      0.06057n ±  8%   0.04660n ± 16%  -23.08% (p=0.000 n=10)
Compare/major/tightenconstraint2-8      0.06113n ±  8%   0.04707n ±  1%  -22.99% (p=0.000 n=10)
Compare/major/tocomparable-8            0.05953n ±  2%   0.04607n ±  1%  -22.62% (p=0.000 n=10)
Compare/major/toconstraint-8            0.05935n ± 21%   0.04633n ±  1%  -21.95% (p=0.000 n=10)
Compare/major/tononfunc-8               0.05867n ±  2%   0.04649n ± 11%  -20.77% (p=0.000 n=10)
Compare/major/tononintf-8               0.05953n ± 20%   0.04629n ±  2%  -22.24% (p=0.000 n=10)
Compare/major/tononstruct-8             0.05916n ±  8%   0.04730n ±  5%  -20.05% (p=0.000 n=10)
Compare/major/unassignablechan-8        0.05520n ±  2%   0.04694n ±  2%  -14.95% (p=0.002 n=10)
Compare/minor/add-8                     0.05568n ±  2%   0.04718n ± 59%        ~ (p=0.138 n=10)
Compare/minor/addfield-8                0.05647n ±  8%   0.04600n ±  3%  -18.55% (p=0.000 n=10)
Compare/minor/addmethod1-8              0.05751n ±  3%   0.04796n ± 11%  -16.61% (p=0.001 n=10)
Compare/minor/addmethod2-8              0.07216n ± 33%   0.06022n ± 41%  -16.55% (p=0.009 n=10)
Compare/minor/addoptparam-8             0.05902n ± 14%   0.05493n ± 13%   -6.93% (p=0.015 n=10)
Compare/minor/addpackage-8              0.06057n ±  8%   0.05512n ± 14%   -9.00% (p=0.015 n=10)
Compare/minor/addtag-8                  0.05783n ± 19%   0.04854n ±  9%  -16.08% (p=0.002 n=10)
Compare/minor/basexx-8                   0.1831n ±  5%    0.1522n ±  6%  -16.85% (p=0.000 n=10)
Compare/minor/bumpgoversion-8           0.05912n ±  2%   0.05106n ± 11%  -13.63% (p=0.000 n=10)
Compare/minor/familiarmethodname-8      0.05885n ±  3%   0.05140n ± 11%  -12.66% (p=0.001 n=10)
Compare/minor/relaxconstraint1-8        0.05765n ±  2%   0.05052n ± 35%        ~ (p=0.143 n=10)
Compare/minor/relaxconstraint2-8        0.05779n ±  4%   0.04732n ± 57%  -18.12% (p=0.022 n=10)
Compare/minor/relaxparam-8              0.05909n ± 29%   0.04871n ± 23%  -17.56% (p=0.009 n=10)
Compare/minor/somecomparabletoany-8     0.06012n ±  8%   0.04752n ±  3%  -20.97% (p=0.000 n=10)
Compare/minor/sometoallcomparable-8     0.06001n ±  6%   0.04731n ± 25%  -21.16% (p=0.001 n=10)
Compare/minor/subcmd-8                   0.1944n ±  3%    0.1761n ± 27%   -9.41% (p=0.023 n=10)
Compare/patchlevel/chstructorder-8      0.06218n ±  6%   0.04813n ±  1%  -22.59% (p=0.000 n=10)
Compare/patchlevel/chtypeunexported-8   0.05886n ±  5%   0.04693n ± 20%  -20.26% (p=0.002 n=10)
Compare/patchlevel/map-8                0.06467n ±  9%   0.04761n ±  7%  -26.38% (p=0.000 n=10)
Compare/patchlevel/pointer-8            0.06072n ±  8%   0.05141n ± 18%  -15.33% (p=0.007 n=10)
Compare/patchlevel/rminternal-8         0.06638n ± 11%   0.05805n ± 12%  -12.55% (p=0.004 n=10)
Compare/patchlevel/rmpackage-8          0.06339n ± 14%   0.05050n ±  8%  -20.33% (p=0.001 n=10)
Compare/patchlevel/rmunexported-8       0.05992n ±  9%   0.04804n ±  7%  -19.84% (p=0.000 n=10)
Compare/patchlevel/slice-8              0.05783n ±  3%   0.04939n ± 22%  -14.59% (p=0.019 n=10)
Compare/none/assignablechan1-8          0.05844n ±  9%   0.04942n ± 10%  -15.43% (p=0.000 n=10)
Compare/none/assignablechan2-8          0.05734n ±  2%   0.05014n ±  6%  -12.56% (p=0.002 n=10)
Compare/none/basexx-8                    0.1863n ±  2%    0.1533n ±  7%  -17.74% (p=0.000 n=10)
Compare/none/chconstant-8               0.05747n ± 10%   0.04783n ±  2%  -16.78% (p=0.000 n=10)
Compare/none/comparablefield-8          0.05867n ±  4%   0.04827n ± 26%  -17.73% (p=0.015 n=10)
Compare/none/renametypeparam-8          0.05793n ±  2%   0.05821n ±  6%        ~ (p=0.971 n=10)
Compare/none/reordered-8                0.05668n ±  1%   0.06203n ± 13%   +9.43% (p=0.000 n=10)
Compare/none/reorderterms-8             0.05684n ±  4%   0.05907n ± 10%   +3.93% (p=0.005 n=10)
Compare/none/sameintf-8                 0.05427n ±  3%   0.06649n ±  5%  +22.51% (p=0.000 n=10)
Compare/none/sametags-8                 0.05604n ±  7%   0.06003n ± 10%   +7.12% (p=0.005 n=10)
geomean                                 0.06303n         0.05230n        -17.02%
github-actions[bot] commented 5 months ago

Modver result

This report was generated by Modver, a Go package and command that helps you obey semantic versioning rules in your Go module.

This PR does not require a change in your module’s version number. (You might still consider bumping the patchlevel anyway.)