Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid extra allocation using buffer pools #370

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fziglio
Copy link

@fziglio fziglio commented Apr 27, 2022

Inserting directly a slice into a sync.Pool object caused the allocation for an extra object every Put call.
Avoid it using unsafe.Pointer to the underlying array.

Inserting directly a slice into a sync.Pool object caused
the allocation for an extra object every Put call.
Avoid it using unsafe.Pointer to the underlying array.

Signed-off-by: Frediano Ziglio <[email protected]>
@fziglio
Copy link
Author

fziglio commented Aug 9, 2022

Before

cpu: Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
BenchmarkEJ_Unmarshal_M-8                   	   46212	     24631 ns/op	 528.76 MB/s	    9512 B/op	     126 allocs/op
BenchmarkEJ_Unmarshal_S-8                   	 2706932	       422.3 ns/op	 194.19 MB/s	     128 B/op	       3 allocs/op
BenchmarkEJ_Marshal_M-8                     	  123048	      9018 ns/op	 992.12 MB/s	   10317 B/op	      10 allocs/op
BenchmarkEJ_Marshal_L-8                     	    2662	    432869 ns/op	1033.59 MB/s	  458810 B/op	      29 allocs/op
BenchmarkEJ_Marshal_L_ToWriter-8            	    2616	    419877 ns/op	1065.57 MB/s	  429469 B/op	      26 allocs/op
BenchmarkEJ_Marshal_M_Parallel-8            	  377967	      3146 ns/op	4139.86 MB/s	   10286 B/op	       9 allocs/op
BenchmarkEJ_Marshal_M_ToWriter-8            	  118784	     11216 ns/op	 797.72 MB/s	    8332 B/op	       9 allocs/op
BenchmarkEJ_Marshal_M_ToWriter_Parallel-8   	  314870	      5425 ns/op	1649.16 MB/s	    8365 B/op	       9 allocs/op
BenchmarkEJ_Marshal_L_Parallel-8            	    4176	    294338 ns/op	1520.05 MB/s	  463311 B/op	      29 allocs/op
BenchmarkEJ_Marshal_L_ToWriter_Parallel-8   	    3612	    299408 ns/op	1494.32 MB/s	  430247 B/op	      26 allocs/op
BenchmarkEJ_Marshal_S-8                     	 7064870	       157.7 ns/op	 513.67 MB/s	     128 B/op	       1 allocs/op
BenchmarkEJ_Marshal_S_Parallel-8            	18573440	        86.81 ns/op	 933.10 MB/s	     128 B/op	       1 allocs/op
PASS

After

cpu: Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
BenchmarkEJ_Unmarshal_M-8                   	   42735	     24310 ns/op	 535.75 MB/s	    9512 B/op	     126 allocs/op
BenchmarkEJ_Unmarshal_S-8                   	 2920184	       420.3 ns/op	 195.09 MB/s	     128 B/op	       3 allocs/op
BenchmarkEJ_Marshal_M-8                     	  136938	      8853 ns/op	1010.66 MB/s	   10195 B/op	       5 allocs/op
BenchmarkEJ_Marshal_L-8                     	    2827	    422204 ns/op	1059.70 MB/s	  455466 B/op	       9 allocs/op
BenchmarkEJ_Marshal_L_ToWriter-8            	    2788	    410771 ns/op	1089.20 MB/s	  429380 B/op	      25 allocs/op
BenchmarkEJ_Marshal_M_Parallel-8            	  358410	      3348 ns/op	3889.56 MB/s	   10172 B/op	       4 allocs/op
BenchmarkEJ_Marshal_M_ToWriter-8            	  103680	     10921 ns/op	 819.27 MB/s	    8308 B/op	       8 allocs/op
BenchmarkEJ_Marshal_M_ToWriter_Parallel-8   	  290469	      5522 ns/op	1620.16 MB/s	    8340 B/op	       8 allocs/op
BenchmarkEJ_Marshal_L_Parallel-8            	    4010	    288841 ns/op	1548.98 MB/s	  463335 B/op	      10 allocs/op
BenchmarkEJ_Marshal_L_ToWriter_Parallel-8   	    3938	    308947 ns/op	1448.18 MB/s	  429638 B/op	      25 allocs/op
BenchmarkEJ_Marshal_S-8                     	 7016001	       160.2 ns/op	 505.67 MB/s	     128 B/op	       1 allocs/op
BenchmarkEJ_Marshal_S_Parallel-8            	11824609	        93.46 ns/op	 866.65 MB/s	     128 B/op	       1 allocs/op
PASS

@fziglio
Copy link
Author

fziglio commented Nov 14, 2022

ping

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.

1 participant