-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve performance by pre-compiling regexes (#1439)
* perf: Precompile regexps * perf: Cache dynamic regexps
- Loading branch information
Showing
2 changed files
with
41 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c55ed50
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
BenchmarkCachedRaw
17.64
ns/op 0 B/op 0 allocs/op18.19
ns/op 0 B/op 0 allocs/op0.97
BenchmarkCachedRaw - ns/op
17.64
ns/op18.19
ns/op0.97
BenchmarkCachedRaw - B/op
0
B/op0
B/op1
BenchmarkCachedRaw - allocs/op
0
allocs/op0
allocs/op1
BenchmarkCachedBasicModel
184.7
ns/op 104 B/op 4 allocs/op183.5
ns/op 104 B/op 4 allocs/op1.01
BenchmarkCachedBasicModel - ns/op
184.7
ns/op183.5
ns/op1.01
BenchmarkCachedBasicModel - B/op
104
B/op104
B/op1
BenchmarkCachedBasicModel - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedRBACModel
182.6
ns/op 104 B/op 4 allocs/op180.6
ns/op 104 B/op 4 allocs/op1.01
BenchmarkCachedRBACModel - ns/op
182.6
ns/op180.6
ns/op1.01
BenchmarkCachedRBACModel - B/op
104
B/op104
B/op1
BenchmarkCachedRBACModel - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedRBACModelSmall
189.7
ns/op 104 B/op 4 allocs/op184.3
ns/op 104 B/op 4 allocs/op1.03
BenchmarkCachedRBACModelSmall - ns/op
189.7
ns/op184.3
ns/op1.03
BenchmarkCachedRBACModelSmall - B/op
104
B/op104
B/op1
BenchmarkCachedRBACModelSmall - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedRBACModelMedium
193.6
ns/op 104 B/op 4 allocs/op192.1
ns/op 104 B/op 4 allocs/op1.01
BenchmarkCachedRBACModelMedium - ns/op
193.6
ns/op192.1
ns/op1.01
BenchmarkCachedRBACModelMedium - B/op
104
B/op104
B/op1
BenchmarkCachedRBACModelMedium - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedRBACModelLarge
169.2
ns/op 96 B/op 3 allocs/op163.6
ns/op 96 B/op 3 allocs/op1.03
BenchmarkCachedRBACModelLarge - ns/op
169.2
ns/op163.6
ns/op1.03
BenchmarkCachedRBACModelLarge - B/op
96
B/op96
B/op1
BenchmarkCachedRBACModelLarge - allocs/op
3
allocs/op3
allocs/op1
BenchmarkCachedRBACModelWithResourceRoles
187.2
ns/op 104 B/op 4 allocs/op193.1
ns/op 104 B/op 4 allocs/op0.97
BenchmarkCachedRBACModelWithResourceRoles - ns/op
187.2
ns/op193.1
ns/op0.97
BenchmarkCachedRBACModelWithResourceRoles - B/op
104
B/op104
B/op1
BenchmarkCachedRBACModelWithResourceRoles - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedRBACModelWithDomains
191.5
ns/op 120 B/op 4 allocs/op200.1
ns/op 120 B/op 4 allocs/op0.96
BenchmarkCachedRBACModelWithDomains - ns/op
191.5
ns/op200.1
ns/op0.96
BenchmarkCachedRBACModelWithDomains - B/op
120
B/op120
B/op1
BenchmarkCachedRBACModelWithDomains - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedABACModel
2793
ns/op 1539 B/op 18 allocs/op3054
ns/op 1535 B/op 18 allocs/op0.91
BenchmarkCachedABACModel - ns/op
2793
ns/op3054
ns/op0.91
BenchmarkCachedABACModel - B/op
1539
B/op1535
B/op1.00
BenchmarkCachedABACModel - allocs/op
18
allocs/op18
allocs/op1
BenchmarkCachedKeyMatchModel
192
ns/op 152 B/op 4 allocs/op212
ns/op 152 B/op 4 allocs/op0.91
BenchmarkCachedKeyMatchModel - ns/op
192
ns/op212
ns/op0.91
BenchmarkCachedKeyMatchModel - B/op
152
B/op152
B/op1
BenchmarkCachedKeyMatchModel - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedRBACModelWithDeny
183.1
ns/op 104 B/op 4 allocs/op193.4
ns/op 104 B/op 4 allocs/op0.95
BenchmarkCachedRBACModelWithDeny - ns/op
183.1
ns/op193.4
ns/op0.95
BenchmarkCachedRBACModelWithDeny - B/op
104
B/op104
B/op1
BenchmarkCachedRBACModelWithDeny - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedPriorityModel
179.2
ns/op 104 B/op 4 allocs/op189.7
ns/op 104 B/op 4 allocs/op0.94
BenchmarkCachedPriorityModel - ns/op
179.2
ns/op189.7
ns/op0.94
BenchmarkCachedPriorityModel - B/op
104
B/op104
B/op1
BenchmarkCachedPriorityModel - allocs/op
4
allocs/op4
allocs/op1
BenchmarkCachedWithEnforceContext
297.4
ns/op 240 B/op 5 allocs/op315.7
ns/op 240 B/op 5 allocs/op0.94
BenchmarkCachedWithEnforceContext - ns/op
297.4
ns/op315.7
ns/op0.94
BenchmarkCachedWithEnforceContext - B/op
240
B/op240
B/op1
BenchmarkCachedWithEnforceContext - allocs/op
5
allocs/op5
allocs/op1
BenchmarkCachedRBACModelMediumParallel
176.4
ns/op 105 B/op 4 allocs/op171.7
ns/op 105 B/op 4 allocs/op1.03
BenchmarkCachedRBACModelMediumParallel - ns/op
176.4
ns/op171.7
ns/op1.03
BenchmarkCachedRBACModelMediumParallel - B/op
105
B/op105
B/op1
BenchmarkCachedRBACModelMediumParallel - allocs/op
4
allocs/op4
allocs/op1
BenchmarkHasPolicySmall
507.2
ns/op 150 B/op 6 allocs/op536.5
ns/op 150 B/op 6 allocs/op0.95
BenchmarkHasPolicySmall - ns/op
507.2
ns/op536.5
ns/op0.95
BenchmarkHasPolicySmall - B/op
150
B/op150
B/op1
BenchmarkHasPolicySmall - allocs/op
6
allocs/op6
allocs/op1
BenchmarkHasPolicyMedium
544.2
ns/op 157 B/op 6 allocs/op610.4
ns/op 157 B/op 6 allocs/op0.89
BenchmarkHasPolicyMedium - ns/op
544.2
ns/op610.4
ns/op0.89
BenchmarkHasPolicyMedium - B/op
157
B/op157
B/op1
BenchmarkHasPolicyMedium - allocs/op
6
allocs/op6
allocs/op1
BenchmarkHasPolicyLarge
561.5
ns/op 165 B/op 7 allocs/op590.5
ns/op 165 B/op 7 allocs/op0.95
BenchmarkHasPolicyLarge - ns/op
561.5
ns/op590.5
ns/op0.95
BenchmarkHasPolicyLarge - B/op
165
B/op165
B/op1
BenchmarkHasPolicyLarge - allocs/op
7
allocs/op7
allocs/op1
BenchmarkAddPolicySmall
559.1
ns/op 152 B/op 6 allocs/op581.2
ns/op 152 B/op 6 allocs/op0.96
BenchmarkAddPolicySmall - ns/op
559.1
ns/op581.2
ns/op0.96
BenchmarkAddPolicySmall - B/op
152
B/op152
B/op1
BenchmarkAddPolicySmall - allocs/op
6
allocs/op6
allocs/op1
BenchmarkAddPolicyMedium
639.1
ns/op 169 B/op 7 allocs/op757.5
ns/op 171 B/op 7 allocs/op0.84
BenchmarkAddPolicyMedium - ns/op
639.1
ns/op757.5
ns/op0.84
BenchmarkAddPolicyMedium - B/op
169
B/op171
B/op0.99
BenchmarkAddPolicyMedium - allocs/op
7
allocs/op7
allocs/op1
BenchmarkAddPolicyLarge
1310
ns/op 464 B/op 9 allocs/op1298
ns/op 448 B/op 9 allocs/op1.01
BenchmarkAddPolicyLarge - ns/op
1310
ns/op1298
ns/op1.01
BenchmarkAddPolicyLarge - B/op
464
B/op448
B/op1.04
BenchmarkAddPolicyLarge - allocs/op
9
allocs/op9
allocs/op1
BenchmarkRemovePolicySmall
509.5
ns/op 166 B/op 7 allocs/op547.8
ns/op 166 B/op 7 allocs/op0.93
BenchmarkRemovePolicySmall - ns/op
509.5
ns/op547.8
ns/op0.93
BenchmarkRemovePolicySmall - B/op
166
B/op166
B/op1
BenchmarkRemovePolicySmall - allocs/op
7
allocs/op7
allocs/op1
BenchmarkRemovePolicyMedium
583.2
ns/op 175 B/op 7 allocs/op628
ns/op 175 B/op 7 allocs/op0.93
BenchmarkRemovePolicyMedium - ns/op
583.2
ns/op628
ns/op0.93
BenchmarkRemovePolicyMedium - B/op
175
B/op175
B/op1
BenchmarkRemovePolicyMedium - allocs/op
7
allocs/op7
allocs/op1
BenchmarkRemovePolicyLarge
1388
ns/op 284 B/op 12 allocs/op1164
ns/op 279 B/op 12 allocs/op1.19
BenchmarkRemovePolicyLarge - ns/op
1388
ns/op1164
ns/op1.19
BenchmarkRemovePolicyLarge - B/op
284
B/op279
B/op1.02
BenchmarkRemovePolicyLarge - allocs/op
12
allocs/op12
allocs/op1
BenchmarkRaw
17.66
ns/op 0 B/op 0 allocs/op18.19
ns/op 0 B/op 0 allocs/op0.97
BenchmarkRaw - ns/op
17.66
ns/op18.19
ns/op0.97
BenchmarkRaw - B/op
0
B/op0
B/op1
BenchmarkRaw - allocs/op
0
allocs/op0
allocs/op1
BenchmarkBasicModel
3716
ns/op 1509 B/op 17 allocs/op3874
ns/op 1502 B/op 17 allocs/op0.96
BenchmarkBasicModel - ns/op
3716
ns/op3874
ns/op0.96
BenchmarkBasicModel - B/op
1509
B/op1502
B/op1.00
BenchmarkBasicModel - allocs/op
17
allocs/op17
allocs/op1
BenchmarkRBACModel
5448
ns/op 2066 B/op 35 allocs/op5734
ns/op 2053 B/op 35 allocs/op0.95
BenchmarkRBACModel - ns/op
5448
ns/op5734
ns/op0.95
BenchmarkRBACModel - B/op
2066
B/op2053
B/op1.01
BenchmarkRBACModel - allocs/op
35
allocs/op35
allocs/op1
BenchmarkRBACModelSizes/small
50128
ns/op 20271 B/op 480 allocs/op51141
ns/op 20201 B/op 480 allocs/op0.98
BenchmarkRBACModelSizes/small - ns/op
50128
ns/op51141
ns/op0.98
BenchmarkRBACModelSizes/small - B/op
20271
B/op20201
B/op1.00
BenchmarkRBACModelSizes/small - allocs/op
480
allocs/op480
allocs/op1
BenchmarkRBACModelSizes/medium
498273
ns/op 191782 B/op 4828 allocs/op538514
ns/op 191784 B/op 4829 allocs/op0.93
BenchmarkRBACModelSizes/medium - ns/op
498273
ns/op538514
ns/op0.93
BenchmarkRBACModelSizes/medium - B/op
191782
B/op191784
B/op1.00
BenchmarkRBACModelSizes/medium - allocs/op
4828
allocs/op4829
allocs/op1.00
BenchmarkRBACModelSizes/large
5167806
ns/op 1900583 B/op 48199 allocs/op5780629
ns/op 1901508 B/op 48223 allocs/op0.89
BenchmarkRBACModelSizes/large - ns/op
5167806
ns/op5780629
ns/op0.89
BenchmarkRBACModelSizes/large - B/op
1900583
B/op1901508
B/op1.00
BenchmarkRBACModelSizes/large - allocs/op
48199
allocs/op48223
allocs/op1.00
BenchmarkRBACModelSmall
61231
ns/op 20291 B/op 615 allocs/op61570
ns/op 20264 B/op 615 allocs/op0.99
BenchmarkRBACModelSmall - ns/op
61231
ns/op61570
ns/op0.99
BenchmarkRBACModelSmall - B/op
20291
B/op20264
B/op1.00
BenchmarkRBACModelSmall - allocs/op
615
allocs/op615
allocs/op1
BenchmarkRBACModelMedium
568391
ns/op 194523 B/op 6018 allocs/op604710
ns/op 194611 B/op 6018 allocs/op0.94
BenchmarkRBACModelMedium - ns/op
568391
ns/op604710
ns/op0.94
BenchmarkRBACModelMedium - B/op
194523
B/op194611
B/op1.00
BenchmarkRBACModelMedium - allocs/op
6018
allocs/op6018
allocs/op1
BenchmarkRBACModelLarge
5983377
ns/op 1933154 B/op 60290 allocs/op6142297
ns/op 1934305 B/op 60334 allocs/op0.97
BenchmarkRBACModelLarge - ns/op
5983377
ns/op6142297
ns/op0.97
BenchmarkRBACModelLarge - B/op
1933154
B/op1934305
B/op1.00
BenchmarkRBACModelLarge - allocs/op
60290
allocs/op60334
allocs/op1.00
BenchmarkRBACModelWithResourceRoles
5295
ns/op 2738 B/op 28 allocs/op5485
ns/op 2719 B/op 28 allocs/op0.97
BenchmarkRBACModelWithResourceRoles - ns/op
5295
ns/op5485
ns/op0.97
BenchmarkRBACModelWithResourceRoles - B/op
2738
B/op2719
B/op1.01
BenchmarkRBACModelWithResourceRoles - allocs/op
28
allocs/op28
allocs/op1
BenchmarkRBACModelWithDomains
5066
ns/op 1826 B/op 25 allocs/op5348
ns/op 1819 B/op 25 allocs/op0.95
BenchmarkRBACModelWithDomains - ns/op
5066
ns/op5348
ns/op0.95
BenchmarkRBACModelWithDomains - B/op
1826
B/op1819
B/op1.00
BenchmarkRBACModelWithDomains - allocs/op
25
allocs/op25
allocs/op1
BenchmarkABACModel
2830
ns/op 1537 B/op 17 allocs/op2914
ns/op 1528 B/op 17 allocs/op0.97
BenchmarkABACModel - ns/op
2830
ns/op2914
ns/op0.97
BenchmarkABACModel - B/op
1537
B/op1528
B/op1.01
BenchmarkABACModel - allocs/op
17
allocs/op17
allocs/op1
BenchmarkABACRuleModel
4021723
ns/op 1330094 B/op 40092 allocs/op4095359
ns/op 1316533 B/op 40090 allocs/op0.98
BenchmarkABACRuleModel - ns/op
4021723
ns/op4095359
ns/op0.98
BenchmarkABACRuleModel - B/op
1330094
B/op1316533
B/op1.01
BenchmarkABACRuleModel - allocs/op
40092
allocs/op40090
allocs/op1.00
BenchmarkKeyMatchModel
6184
ns/op 3070 B/op 37 allocs/op6341
ns/op 3051 B/op 37 allocs/op0.98
BenchmarkKeyMatchModel - ns/op
6184
ns/op6341
ns/op0.98
BenchmarkKeyMatchModel - B/op
3070
B/op3051
B/op1.01
BenchmarkKeyMatchModel - allocs/op
37
allocs/op37
allocs/op1
BenchmarkRBACModelWithDeny
7036
ns/op 2487 B/op 49 allocs/op7183
ns/op 2467 B/op 49 allocs/op0.98
BenchmarkRBACModelWithDeny - ns/op
7036
ns/op7183
ns/op0.98
BenchmarkRBACModelWithDeny - B/op
2487
B/op2467
B/op1.01
BenchmarkRBACModelWithDeny - allocs/op
49
allocs/op49
allocs/op1
BenchmarkPriorityModel
4209
ns/op 1766 B/op 22 allocs/op4394
ns/op 1754 B/op 22 allocs/op0.96
BenchmarkPriorityModel - ns/op
4209
ns/op4394
ns/op0.96
BenchmarkPriorityModel - B/op
1766
B/op1754
B/op1.01
BenchmarkPriorityModel - allocs/op
22
allocs/op22
allocs/op1
BenchmarkRBACModelWithDomainPatternLarge
13501
ns/op 8693 B/op 72 allocs/op24595
ns/op 16711 B/op 164 allocs/op0.55
BenchmarkRBACModelWithDomainPatternLarge - ns/op
13501
ns/op24595
ns/op0.55
BenchmarkRBACModelWithDomainPatternLarge - B/op
8693
B/op16711
B/op0.52
BenchmarkRBACModelWithDomainPatternLarge - allocs/op
72
allocs/op164
allocs/op0.44
BenchmarkRoleManagerSmall
72109
ns/op 11955 B/op 797 allocs/op71739
ns/op 11954 B/op 797 allocs/op1.01
BenchmarkRoleManagerSmall - ns/op
72109
ns/op71739
ns/op1.01
BenchmarkRoleManagerSmall - B/op
11955
B/op11954
B/op1.00
BenchmarkRoleManagerSmall - allocs/op
797
allocs/op797
allocs/op1
BenchmarkRoleManagerMedium
732165
ns/op 125914 B/op 8741 allocs/op742295
ns/op 125913 B/op 8741 allocs/op0.99
BenchmarkRoleManagerMedium - ns/op
732165
ns/op742295
ns/op0.99
BenchmarkRoleManagerMedium - B/op
125914
B/op125913
B/op1.00
BenchmarkRoleManagerMedium - allocs/op
8741
allocs/op8741
allocs/op1
BenchmarkRoleManagerLarge
7964602
ns/op 1349926 B/op 89741 allocs/op9529544
ns/op 1349924 B/op 89741 allocs/op0.84
BenchmarkRoleManagerLarge - ns/op
7964602
ns/op9529544
ns/op0.84
BenchmarkRoleManagerLarge - B/op
1349926
B/op1349924
B/op1.00
BenchmarkRoleManagerLarge - allocs/op
89741
allocs/op89741
allocs/op1
BenchmarkBuildRoleLinksWithPatternLarge
331510685
ns/op 90236379 B/op 3599770 allocs/op6490055533
ns/op 5333333872 B/op 60945594 allocs/op0.05107979173897155
BenchmarkBuildRoleLinksWithPatternLarge - ns/op
331510685
ns/op6490055533
ns/op0.05107979173897155
BenchmarkBuildRoleLinksWithPatternLarge - B/op
90236379
B/op5333333872
B/op0.016919319353648744
BenchmarkBuildRoleLinksWithPatternLarge - allocs/op
3599770
allocs/op60945594
allocs/op0.05906530339174314
BenchmarkBuildRoleLinksWithDomainPatternLarge
12068710
ns/op 4708833 B/op 145247 allocs/op178446545
ns/op 141263329 B/op 1676405 allocs/op0.06763207435593667
BenchmarkBuildRoleLinksWithDomainPatternLarge - ns/op
12068710
ns/op178446545
ns/op0.06763207435593667
BenchmarkBuildRoleLinksWithDomainPatternLarge - B/op
4708833
B/op141263329
B/op0.033333725272749304
BenchmarkBuildRoleLinksWithDomainPatternLarge - allocs/op
145247
allocs/op1676405
allocs/op0.08664195107984049
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge
341165478
ns/op 91964061 B/op 3679273 allocs/op6523634217
ns/op 5474425808 B/op 62556841 allocs/op0.052296843546340115
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge - ns/op
341165478
ns/op6523634217
ns/op0.052296843546340115
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge - B/op
91964061
B/op5474425808
B/op0.016798850550793692
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge - allocs/op
3679273
allocs/op62556841
allocs/op0.058814878455899014
BenchmarkHasLinkWithPatternLarge
1146
ns/op 177 B/op 13 allocs/op10895
ns/op 7593 B/op 111 allocs/op0.11
BenchmarkHasLinkWithPatternLarge - ns/op
1146
ns/op10895
ns/op0.11
BenchmarkHasLinkWithPatternLarge - B/op
177
B/op7593
B/op0.023310944290794153
BenchmarkHasLinkWithPatternLarge - allocs/op
13
allocs/op111
allocs/op0.12
BenchmarkHasLinkWithDomainPatternLarge
478.7
ns/op 80 B/op 5 allocs/op495.6
ns/op 80 B/op 5 allocs/op0.97
BenchmarkHasLinkWithDomainPatternLarge - ns/op
478.7
ns/op495.6
ns/op0.97
BenchmarkHasLinkWithDomainPatternLarge - B/op
80
B/op80
B/op1
BenchmarkHasLinkWithDomainPatternLarge - allocs/op
5
allocs/op5
allocs/op1
BenchmarkHasLinkWithPatternAndDomainPatternLarge
1116
ns/op 177 B/op 13 allocs/op10972
ns/op 7589 B/op 111 allocs/op0.10
BenchmarkHasLinkWithPatternAndDomainPatternLarge - ns/op
1116
ns/op10972
ns/op0.10
BenchmarkHasLinkWithPatternAndDomainPatternLarge - B/op
177
B/op7589
B/op0.02332323099222559
BenchmarkHasLinkWithPatternAndDomainPatternLarge - allocs/op
13
allocs/op111
allocs/op0.12
This comment was automatically generated by workflow using github-action-benchmark.
c55ed50
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.10
.BenchmarkRemovePolicyLarge
1388
ns/op 284 B/op 12 allocs/op1164
ns/op 279 B/op 12 allocs/op1.19
BenchmarkRemovePolicyLarge - ns/op
1388
ns/op1164
ns/op1.19
This comment was automatically generated by workflow using github-action-benchmark.