Skip to content

cvss: performance pass - #1985

Open
hdonnay wants to merge 3 commits into
quay:mainfrom
hdonnay:hack/perf/cvss
Open

cvss: performance pass#1985
hdonnay wants to merge 3 commits into
quay:mainfrom
hdonnay:hack/perf/cvss

Conversation

@hdonnay

@hdonnay hdonnay commented Aug 14, 2026

Copy link
Copy Markdown
Member

These changes add benchmarks, then implements encoding.TextAppender in search of minimizing allocations.

Results from my machine
% go test -bench .
goos: linux
goarch: amd64
pkg: github.com/quay/claircore/toolkit/types/cvss
cpu: 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz
BenchmarkAppend/V2/List/#00-16     	 6326913	       193.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V2/List/#01-16     	 6217306	       205.1 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V2/List/#02-16     	 5661710	       219.2 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V2/List/#03-16     	 5883469	       208.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V2/List/#04-16     	 5783688	       207.1 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V2/List/#05-16     	 6741308	       187.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V2/List/#06-16     	 5993172	       217.9 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V2/List/#07-16     	 6734221	       186.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V2/List/#08-16     	 6862696	       186.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V2/List/#09-16     	 8192502	       148.9 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V2/Heartbleed-16   	 6769226	       177.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V3/List/#00-16     	 2831019	       428.5 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V3/List/#01-16     	 3193236	       384.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V3/List/#02-16     	 2889051	       425.9 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V3/List/#03-16     	 2818426	       442.1 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V3/List/#04-16     	 3184968	       388.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V3/List/#05-16     	 3046934	       393.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V3/List/#06-16     	 2899002	       424.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V3/List/#07-16     	 3213680	       387.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V3/List/#08-16     	 3069540	       394.2 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V3/List/#09-16     	 3483903	       348.1 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V3/Heartbleed-16   	 2783239	       443.5 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V4/List/#00-16     	 1902640	       631.7 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V4/List/#01-16     	 1925016	       625.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V4/List/#02-16     	 2151219	       569.7 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V4/List/#03-16     	 1862679	       646.2 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V4/List/#04-16     	 2123660	       572.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V4/List/#05-16     	 1927284	       633.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V4/List/#06-16     	 2286070	       537.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V4/List/#07-16     	 2324389	       585.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V4/List/#08-16     	 2381037	       512.5 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V4/List/#09-16     	 2069151	       585.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V4/B-16            	 2162353	       556.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V4/BT-16           	 2351097	       526.2 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V4/BE-16           	 2432040	       497.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkAppend/V4/BTES-16         	 3854163	       325.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkMarshal/V2/List/#00-16    	 6113946	       255.8 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V2/List/#01-16    	 3961953	       282.9 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V2/List/#02-16    	 4597748	       267.3 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V2/List/#03-16    	 4881979	       278.9 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V2/List/#04-16    	 4464517	       262.6 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V2/List/#05-16    	 4484348	       266.8 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V2/List/#06-16    	 4374933	       259.9 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V2/List/#07-16    	 4550954	       234.2 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V2/List/#08-16    	 4837461	       246.9 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V2/List/#09-16    	 5196676	       224.5 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V2/Heartbleed-16  	 4462342	       328.9 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V3/List/#00-16    	 2551840	       459.4 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V3/List/#01-16    	 2706554	       454.5 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V3/List/#02-16    	 2640318	       427.4 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V3/List/#03-16    	 2758448	       450.8 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V3/List/#04-16    	 2862756	       437.2 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V3/List/#05-16    	 2762264	       437.2 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V3/List/#06-16    	 2892007	       443.2 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V3/List/#07-16    	 2678826	       465.6 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V3/List/#08-16    	 2852010	       439.6 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V3/List/#09-16    	 2693488	       442.6 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V3/Heartbleed-16  	 2567743	       444.2 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V4/List/#00-16    	 2008812	       607.8 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V4/List/#01-16    	 2023903	       593.0 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V4/List/#02-16    	 2024036	       588.3 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V4/List/#03-16    	 2094199	       593.6 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V4/List/#04-16    	 2007337	       604.4 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V4/List/#05-16    	 1962201	       606.7 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V4/List/#06-16    	 2013025	       585.8 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V4/List/#07-16    	 1902122	       639.4 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V4/List/#08-16    	 1986160	       607.1 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V4/List/#09-16    	 2002484	       611.5 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V4/B-16           	 1977696	       611.8 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V4/BT-16          	 2027934	       594.2 ns/op	     128 B/op	       1 allocs/op
BenchmarkMarshal/V4/BE-16          	 1597364	       712.4 ns/op	     384 B/op	       2 allocs/op
BenchmarkMarshal/V4/BTES-16        	 2026893	       570.8 ns/op	     384 B/op	       2 allocs/op
BenchmarkUnmarshal/V2/List/#00-16  	 2257981	       544.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V2/List/#01-16  	 2607223	       469.9 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V2/List/#02-16  	 6222835	       197.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V2/List/#03-16  	 2481720	       486.9 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V2/List/#04-16  	 2468229	       489.2 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V2/List/#05-16  	 3771990	       329.7 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V2/List/#06-16  	 2235807	       539.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V2/List/#07-16  	 2692390	       458.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V2/List/#08-16  	 2216068	       550.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V2/List/#09-16  	 2510408	       485.5 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V2/Heartbleed-16         	 5822320	       218.5 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V3/List/#00-16           	 3556538	       348.1 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V3/List/#01-16           	 3420270	       351.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V3/List/#02-16           	 3572031	       343.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V3/List/#03-16           	 4156965	       300.5 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V3/List/#04-16           	 3576170	       347.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V3/List/#05-16           	 4079590	       306.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V3/List/#06-16           	 3935389	       306.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V3/List/#07-16           	 3619483	       341.7 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V3/List/#08-16           	 3578527	       343.7 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V3/List/#09-16           	 4317814	       290.1 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V3/Heartbleed-16         	 3144542	       370.9 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V4/List/#00-16           	 2705108	       453.9 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V4/List/#01-16           	 2558763	       462.9 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V4/List/#02-16           	 2885755	       426.7 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V4/List/#03-16           	 3126038	       389.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V4/List/#04-16           	 2322171	       521.7 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V4/List/#05-16           	 3218946	       384.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V4/List/#06-16           	 2873418	       416.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V4/List/#07-16           	 2787546	       431.1 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V4/List/#08-16           	 3353396	       366.9 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V4/List/#09-16           	 2441080	       499.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V4/B-16                  	 2669022	       466.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V4/BT-16                 	 2424678	       500.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V4/BE-16                 	 1000000	      1064 ns/op	       0 B/op	       0 allocs/op
BenchmarkUnmarshal/V4/BTES-16               	  943716	      1287 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/quay/claircore/toolkit/types/cvss	132.164s

@hdonnay
hdonnay requested review from a team as code owners August 14, 2026 17:58
@hdonnay
hdonnay requested a review from crozzy August 14, 2026 17:58
This restructures the benchmarks and adds an `encoding.TextMarshaler`
benchmark.

Signed-off-by: Hank Donnay <hdonnay@redhat.com>
Change-Id: I9f83a521ac153eb88af8185ccde0562f6a6a6964
This is automated modernization rewrites.

Signed-off-by: Hank Donnay <hdonnay@redhat.com>
Change-Id: I949ea3ebad46f54e26b19188064994556a6a6964
This implements the new interface, redefines `encoding.TextMarshaler`
using it, and adds benchmarks.

The goal is to have `AppendText` do no unavoidable allocations, meaning
that if the input slice has sufficient capacity there are no additional
heap allocations to populate it.

Signed-off-by: Hank Donnay <hdonnay@redhat.com>
Change-Id: I50157434eb16073a14edb2b4bec253966a6a6964
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant