Skip to content

Conversation

@vastonus
Copy link

@vastonus vastonus commented Oct 16, 2025

These changes use b.Loop() to simplify the code and improve performance
Supported by Go Team, more info: https://go.dev/blog/testing-b-loop and https://go.dev/issue/73137.

Before:

go test -run=^$ -bench=. ./pkg/tss                       
goos: darwin
goarch: arm64
pkg: github.com/bandprotocol/chain/v3/pkg/tss
cpu: Apple M3
BenchmarkEncrypt-10                      	  622239	      1948 ns/op
BenchmarkDecrypt-10                      	  669828	      1712 ns/op
BenchmarkHash/1_byte-10                  	 4624423	       259.6 ns/op
BenchmarkHash/4_bytes-10                 	 4632673	       261.5 ns/op
BenchmarkHash/32_bytes-10                	 4561328	       290.9 ns/op
BenchmarkHash/128_bytes-10               	 3918991	       269.3 ns/op
BenchmarkHash/1024_bytes-10              	  654266	      1896 ns/op
BenchmarkHash/8096_bytes-10              	   85849	     13515 ns/op
BenchmarkSumScalars/1_scalar-10          	17542587	        67.59 ns/op
BenchmarkSumScalars/2_scalars-10         	10528258	       114.1 ns/op
BenchmarkSumScalars/4_scalars-10         	 6178672	       197.0 ns/op
BenchmarkSumScalars/8_scalars-10         	 3390189	       355.5 ns/op
BenchmarkSumScalars/16_scalars-10        	 1810102	       664.6 ns/op
BenchmarkSumScalars/20_scalars-10        	 1404478	       852.1 ns/op
BenchmarkSumPoints/1_point-10            	   78704	     15069 ns/op
BenchmarkSumPoints/2_points-10           	   53053	     22634 ns/op
BenchmarkSumPoints/4_points-10           	   31495	     37971 ns/op
BenchmarkSumPoints/8_points-10           	   17428	     68906 ns/op
BenchmarkSumPoints/16_points-10          	    9368	    132542 ns/op
BenchmarkSumPoints/20_points-10          	    7748	    160958 ns/op
BenchmarkSolveScalarPolynomial/1_coefficient-10         	 6145372	       195.3 ns/op
BenchmarkSolveScalarPolynomial/2_coefficients-10        	 3253008	       361.1 ns/op
BenchmarkSolveScalarPolynomial/4_coefficients-10        	 1749273	       686.4 ns/op
BenchmarkSolveScalarPolynomial/8_coefficients-10        	  897830	      1357 ns/op
BenchmarkSolveScalarPolynomial/16_coefficients-10       	  462337	      2669 ns/op
BenchmarkSolveScalarPolynomial/20_coefficients-10       	  370695	      3263 ns/op
BenchmarkSolvePointPolynomial/1_coefficient-10          	   73198	     17317 ns/op
BenchmarkSolvePointPolynomial/2_coefficients-10         	   14152	     88587 ns/op
BenchmarkSolvePointPolynomial/4_coefficients-10         	    4914	    265079 ns/op
BenchmarkSolvePointPolynomial/8_coefficients-10         	    2113	    605937 ns/op
BenchmarkSolvePointPolynomial/16_coefficients-10        	     920	   1328468 ns/op
BenchmarkSolvePointPolynomial/20_coefficients-10        	     732	   1601354 ns/op
BenchmarkSign-10                                        	  131737	      9340 ns/op
BenchmarkVerify-10                                      	   12024	     99999 ns/op
BenchmarkVerifyWithCustomGenerator-10                   	    7956	    154520 ns/op
BenchmarkVerifyWithCustomLagrange-10                    	   10000	    104389 ns/op
PASS
ok  	github.com/bandprotocol/chain/v3/pkg/tss	55.895s

After:

go test -run=^$ -bench=. ./pkg/tss           
goos: darwin
goarch: arm64
pkg: github.com/bandprotocol/chain/v3/pkg/tss
cpu: Apple M3
BenchmarkEncrypt-10                      	  567440	      1928 ns/op
BenchmarkDecrypt-10                      	  703724	      1702 ns/op
BenchmarkHash/1_byte-10                  	 4603222	       261.5 ns/op
BenchmarkHash/4_bytes-10                 	 4622518	       260.3 ns/op
BenchmarkHash/32_bytes-10                	 4561616	       262.3 ns/op
BenchmarkHash/128_bytes-10               	 4521471	       265.7 ns/op
BenchmarkHash/1024_bytes-10              	  652009	      2104 ns/op
BenchmarkHash/8096_bytes-10              	   74715	     13853 ns/op
BenchmarkSumScalars/1_scalar-10          	17728346	        65.99 ns/op
BenchmarkSumScalars/2_scalars-10         	10544089	       139.3 ns/op
BenchmarkSumScalars/4_scalars-10         	 5843629	       199.2 ns/op
BenchmarkSumScalars/8_scalars-10         	 3395602	       354.2 ns/op
BenchmarkSumScalars/16_scalars-10        	 1804046	       673.1 ns/op
BenchmarkSumScalars/20_scalars-10        	 1403095	       853.8 ns/op
BenchmarkSumPoints/1_point-10            	   78387	     15264 ns/op
BenchmarkSumPoints/2_points-10           	   52152	     24108 ns/op
BenchmarkSumPoints/4_points-10           	   30903	     38840 ns/op
BenchmarkSumPoints/8_points-10           	   16618	     70281 ns/op
BenchmarkSumPoints/16_points-10          	    9116	    133503 ns/op
BenchmarkSumPoints/20_points-10          	    7575	    164217 ns/op
BenchmarkSolveScalarPolynomial/1_coefficient-10         	 6180862	       194.0 ns/op
BenchmarkSolveScalarPolynomial/2_coefficients-10        	 3308318	       362.9 ns/op
BenchmarkSolveScalarPolynomial/4_coefficients-10        	 1745617	       688.9 ns/op
BenchmarkSolveScalarPolynomial/8_coefficients-10        	  898023	      1325 ns/op
BenchmarkSolveScalarPolynomial/16_coefficients-10       	  462050	      2600 ns/op
BenchmarkSolveScalarPolynomial/20_coefficients-10       	  370015	      3256 ns/op
BenchmarkSolvePointPolynomial/1_coefficient-10          	   73411	     16180 ns/op
BenchmarkSolvePointPolynomial/2_coefficients-10         	   13491	     88832 ns/op
BenchmarkSolvePointPolynomial/4_coefficients-10         	    4927	    254178 ns/op
BenchmarkSolvePointPolynomial/8_coefficients-10         	    2142	    590076 ns/op
BenchmarkSolvePointPolynomial/16_coefficients-10        	    1026	   1271700 ns/op
BenchmarkSolvePointPolynomial/20_coefficients-10        	     752	   1643294 ns/op
BenchmarkSign-10                                        	  121498	     10410 ns/op
BenchmarkVerify-10                                      	   10000	    105062 ns/op
BenchmarkVerifyWithCustomGenerator-10                   	    7801	    159191 ns/op
BenchmarkVerifyWithCustomLagrange-10                    	   10000	    104541 ns/op
PASS
ok  	github.com/bandprotocol/chain/v3/pkg/tss	52.658s

Fixed: #XXXX

Implementation details

Please ensure the following requirements are met before submitting a pull request:

  • The pull request is targeted against the correct target branch
  • The pull request is linked to an issue with appropriate discussion and an accepted design OR is linked to a spec that describes the work.
  • The pull request includes a description of the implementation/work done in detail.
  • The pull request includes any and all appropriate unit/integration tests
  • You have added a relevant changelog entry to CHANGELOG_UNRELEASED.md
  • You have re-reviewed the files affected by the pull request (e.g. using the Files changed tab in the Github PR explorer)

Signed-off-by: vastonus <vastonus@outlook.com>
@vastonus vastonus requested a review from a team as a code owner October 16, 2025 08:50
@vastonus vastonus requested review from RogerKSI and taobun October 16, 2025 08:50
@vastonus
Copy link
Author

@taobun @RogerKSI Hi, Could you please review this PR at your convenience? Thank you very much.

@vastonus
Copy link
Author

vastonus commented Dec 6, 2025

@RogerKSI Thank you for your approval.

If there's anything need I to do, please feel free to let me know. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants