Skip to content

Conversation

@dulanting
Copy link
Contributor

@dulanting dulanting commented Oct 13, 2025

Description:

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/decoders                  
goos: darwin
goarch: arm64
pkg: github.com/trufflesecurity/trufflehog/v3/pkg/decoders
cpu: Apple M4
BenchmarkFromChunkSmall-10                	 6595539	       181.3 ns/op
BenchmarkFromChunkMedium-10               	  466124	      2224 ns/op
BenchmarkFromChunkLarge-10                	33437010	        34.91 ns/op
BenchmarkDecodeOriginalEscape-10          	50474690	        42.09 ns/op
BenchmarkDecodeCodePoint-10               	  880795	      1218 ns/op
BenchmarkDecodeBraceEscape-10             	48463552	        49.64 ns/op
BenchmarkDecodeLongEscape-10              	43757558	        56.57 ns/op
BenchmarkDecodePerlEscape-10              	46256365	        68.06 ns/op
BenchmarkDecodeCssEscape-10               	50212356	        23.12 ns/op
BenchmarkDecodeHtmlEscape-10              	47056438	        59.62 ns/op
BenchmarkDecodePercentEscape-10           	50229433	        40.58 ns/op
BenchmarkFromChunk_OriginalFormat-10      	  998955	      1168 ns/op
BenchmarkFromChunk_BraceFormat-10         	 1000000	      1168 ns/op
BenchmarkFromChunk_LongFormat-10          	  603687	      2029 ns/op
BenchmarkFromChunk_HtmlFormat-10          	  999502	      1237 ns/op
BenchmarkFromChunk_MixedContent-10        	  198066	      5813 ns/op
BenchmarkFromChunk_NoUnicode-10           	  258198	      4645 ns/op
BenchmarkFromChunk_LargeData-10           	     528	   2244064 ns/op
BenchmarkRegexMatching_AllPatterns-10     	  124023	      9874 ns/op
BenchmarkRegexMatching_NoMatch-10         	  245246	      4659 ns/op
BenchmarkFromChunk_MemoryAllocation-10    	  197952	      6189 ns/op	   14398 B/op	      86 allocs/op
BenchmarkUtf16ToUtf8-10                   	28343331	        38.98 ns/op
Benchmark_extractSubstrings-10            	 5197101	       222.4 ns/op
PASS
ok  	github.com/trufflesecurity/trufflehog/v3/pkg/decoders	41.076s

After:

go test -run=^$ -bench=. ./pkg/decoders                   
goos: darwin
goarch: arm64
pkg: github.com/trufflesecurity/trufflehog/v3/pkg/decoders
cpu: Apple M4
BenchmarkFromChunkSmall-10                	 6542812	       172.2 ns/op
BenchmarkFromChunkMedium-10               	  642433	      1850 ns/op
BenchmarkFromChunkLarge-10                	39467463	        30.15 ns/op
BenchmarkDecodeOriginalEscape-10          	51547774	        23.02 ns/op
BenchmarkDecodeCodePoint-10               	  918812	      1209 ns/op
BenchmarkDecodeBraceEscape-10             	44588186	        25.17 ns/op
BenchmarkDecodeLongEscape-10              	45711601	        26.57 ns/op
BenchmarkDecodePerlEscape-10              	43454577	        26.05 ns/op
BenchmarkDecodeCssEscape-10               	50294870	        23.55 ns/op
BenchmarkDecodeHtmlEscape-10              	43514719	        24.98 ns/op
BenchmarkDecodePercentEscape-10           	49723412	        24.82 ns/op
BenchmarkFromChunk_OriginalFormat-10      	  960178	      1216 ns/op
BenchmarkFromChunk_BraceFormat-10         	 1000000	      1168 ns/op
BenchmarkFromChunk_LongFormat-10          	  625647	      1924 ns/op
BenchmarkFromChunk_HtmlFormat-10          	  992942	      1167 ns/op
BenchmarkFromChunk_MixedContent-10        	  202584	      5804 ns/op
BenchmarkFromChunk_NoUnicode-10           	  253852	      4512 ns/op
BenchmarkFromChunk_LargeData-10           	     536	   2221862 ns/op
BenchmarkRegexMatching_AllPatterns-10     	  125577	      9504 ns/op
BenchmarkRegexMatching_NoMatch-10         	  261069	      4548 ns/op
BenchmarkFromChunk_MemoryAllocation-10    	  195384	      5780 ns/op	   14393 B/op	      86 allocs/op
BenchmarkUtf16ToUtf8-10                   	31611598	        37.37 ns/op
Benchmark_extractSubstrings-10            	 5364784	       224.2 ns/op
PASS
ok  	github.com/trufflesecurity/trufflehog/v3/pkg/decoders	27.924s

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

@dulanting dulanting requested review from a team as code owners October 13, 2025 08:00
@CLAassistant
Copy link

CLAassistant commented Oct 13, 2025

CLA assistant check
All committers have signed the CLA.

@rosecodym
Copy link
Contributor

Thank you for this change, and particularly for the links to commentary explaining it! It's nice to have that stuff in the commit history.

@rosecodym rosecodym merged commit 7afd5da into trufflesecurity:main Oct 14, 2025
13 checks passed
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.

3 participants