Skip to content

Conversation

@brianolson
Copy link
Contributor

No description provided.

@brianolson brianolson changed the title use stack allocated struct to avoid heap&GC churn fixed array in struct instead of heap slice Sep 2, 2024
@brianolson
Copy link
Contributor Author

brianolson commented Sep 2, 2024

winning benchmarks, from go test -memprofile /tmp/cgbench.pprof -run xxx -bench BenchmarkMarshaling

branch
BenchmarkMarshaling-16    	 1705956	       732.9 ns/op	      48 B/op	       1 allocs/op
2741714 48B objects, 1.6 alloc/op

master
BenchmarkMarshaling-16    	 1331407	       863.6 ns/op	      80 B/op	       2 allocs/op
4898996 objects, 3.68 alloc/op (2588711 16B + 2310285 64B)

@brianolson
Copy link
Contributor Author

Applying the same strategy to reading and unmarshalling works, but is smaller because the test objects are lots of allocations. NewCborReader() setup gets better, but is swamped by the rest of of the object unmarshal, but is still an easy improvement.

go test -memprofile /tmp/cgbench.pprof -run xxx -bench BenchmarkUnmarshaling -v -gcflags -m 2> /tmp/go_build_debug

branch
BenchmarkUnmarshaling-16    	  207495	      6459 ns/op	    1772 B/op	      21 allocs/op
NewCborReader 229383 32B (1.11 alloc/op)

master
BenchmarkUnmarshaling-16    	  180823	      6467 ns/op	    1796 B/op	      22 allocs/op
NewCborReader 152924 48B + 131074 16B (1.57 alloc/op)

@whyrusleeping whyrusleeping merged commit 8dc02b3 into whyrusleeping:master Sep 4, 2024
@brianolson brianolson deleted the fewer-alloc branch September 5, 2024 17:00
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