Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: Optimize Filter() for small lists#4282

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 1 commit intomainfromstevenmasley/short_lists
Sep 30, 2022

Conversation

Emyrk
Copy link
Member

@EmyrkEmyrk commentedSep 30, 2022
edited
Loading

What this does

CallingPrepare for authorization has significant overhead costs. This will especially be hit in all of our unit tests. It's cheaper for small lists to just callByRoleName on each element in a short list.

I ran some benchmarks and saw preparing as a user with 0 roles is the fastest at12803317ns. Running aByRoleName is slowest with many roles at968460ns. This means if you took the bestPrepare time and worseByRoleName time, you'd get the performance cutoff at ~13 items in a list (assuming the time afterPrepare()is negligible).

Putting the cutoff at 10 is a safe magic number such that calls below 10will always be faster to do withoutPrepare().

Why do this

If the cost is 12ms in the best case, this time is added to many of our unit tests. Doing this optimization will not only benefit the FE, but also will benefit our test time in the aggregate.

Data used to decide magic number

BenchmarkRBACFilter/PrepareNoRoles-8                  99          12803317 ns/op         2552352 B/op      74203 allocs/opBenchmarkRBACFilter/PrepareAdmin-8                    93          14968142 ns/op         2411699 B/op      73109 allocs/opBenchmarkRBACFilter/PrepareOrgAdmin-8                 69          17115370 ns/op         3222047 B/op      93369 allocs/opBenchmarkRBACFilter/PrepareOrgMember-8                84          17906357 ns/op         3093862 B/op      89507 allocs/opBenchmarkRBACFilter/PrepareManyRoles-8                56          20082477 ns/op         3707931 B/op     106583 allocs/opBenchmarkRBACFilter/PrepareAdminWithScope-8           96          13191942 ns/op         2307629 B/op      69411 allocs/opBenchmarkRBACFilter/OnceNoRoles-8                   4204            304850 ns/op           74356 B/op       1444 allocs/opBenchmarkRBACFilter/OnceAdmin-8                     1443            697019 ns/op          170803 B/op       3645 allocs/opBenchmarkRBACFilter/OnceOrgAdmin-8                  1921            677430 ns/op          163995 B/op       3434 allocs/opBenchmarkRBACFilter/OnceOrgMember-8                 1622            755283 ns/op          179122 B/op       3711 allocs/opBenchmarkRBACFilter/OnceManyRoles-8                 1130            968460 ns/op          227128 B/op       4902 allocs/opBenchmarkRBACFilter/OnceAdminWithScope-8            1405            805665 ns/op          167309 B/op       3560 allocs/op

@EmyrkEmyrk merged commitd8008de intomainSep 30, 2022
@EmyrkEmyrk deleted the stevenmasley/short_lists branchSeptember 30, 2022 19:55
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@sreyasreyasreya approved these changes

@kylecarbskylecarbsAwaiting requested review from kylecarbs

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Emyrk@sreya

[8]ページ先頭

©2009-2025 Movatter.jp