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

Small micro-optimizations around set performance #1702

Merged
merged 6 commits into from
Jan 4, 2024

Conversation

josephschorr
Copy link
Member

@josephschorr josephschorr commented Jan 4, 2024

Before the changes:

BenchmarkAdd-10          	16160137	       128.5 ns/op
BenchmarkCopy-10         	   10000	    465419 ns/op
BenchmarkHas-10          	47101461	        49.75 ns/op
BenchmarkDelete-10       	27999956	        82.98 ns/op
BenchmarkIntersect-10    	   10000	    772631 ns/op
BenchmarkSubtract-10     	   10000	    933186 ns/op

After the changes:

BenchmarkAdd-10          	16139670	       130.6 ns/op
BenchmarkInsert-10       	18618121	       112.0 ns/op
BenchmarkCopy-10         	   10000	    108095 ns/op
BenchmarkHas-10          	46172048	        51.45 ns/op
BenchmarkDelete-10       	31368414	        60.33 ns/op
BenchmarkIntersect-10    	   10000	    386777 ns/op
BenchmarkSubtract-10     	   10000	    474429 ns/op
BenchmarkAsSlice-10      	   14143	    136824 ns/op
BenchmarkEqual-10        	   10000	    275370 ns/op

The big changes are in Copy, Subtract and Equal, all of which are now using the native runtime-provided clone for maps.

The change from Add to Insert (where applicable) and from Remove to Delete also saves 10-20ns per call

@josephschorr josephschorr requested a review from a team as a code owner January 4, 2024 02:06
@github-actions github-actions bot added area/api v1 Affects the v1 API area/CLI Affects the command line area/datastore Affects the storage system area/dispatch Affects dispatching of requests area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Jan 4, 2024
@jzelinskie jzelinskie added this pull request to the merge queue Jan 4, 2024
Merged via the queue into authzed:main with commit c6a1e75 Jan 4, 2024
20 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 4, 2024
@josephschorr josephschorr deleted the set-perf branch January 4, 2024 05:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/api v1 Affects the v1 API area/CLI Affects the command line area/datastore Affects the storage system area/dispatch Affects dispatching of requests area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants