Skip to content

fix: improve AddLink and HasLink with KeyMatch4 pattern performance#801

Merged
hsluoyz merged 1 commit intoapache:masterfrom
sagilio:fix#781
Jul 8, 2021
Merged

fix: improve AddLink and HasLink with KeyMatch4 pattern performance#801
hsluoyz merged 1 commit intoapache:masterfrom
sagilio:fix#781

Conversation

@sagilio
Copy link
Contributor

@sagilio sagilio commented May 23, 2021

fix: #781 and fix: #829

goos: windows
goarch: amd64
pkg: github.com/casbin/casbin/v2
cpu: Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz
Name N Time
BenchmarkBuildRoleLinksWithPatternLarge-16 (Now) 1 1380663800 ns/op
BenchmarkBuildRoleLinksWithPatternLarge-16 1 16264016400 ns/op
BenchmarkBuildRoleLinksWithDomainPatternLarge-16 (Now) 193 6605217 ns/op
BenchmarkBuildRoleLinksWithDomainPatternLarge-16 6 195383033 ns/op
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge-16 (Now) 1 1828370400 ns/op
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge-16 1 62452898100 ns/op
BenchmarkHasLinkWithPatternLarge-16 (Now) 1120 1121191 ns/op
BenchmarkHasLinkWithPatternLarge-16 140 8890446 ns/op
BenchmarkHasLinkWithDomainPatternLarge-16 (Now) 599990 2098 ns/op
BenchmarkHasLinkWithDomainPatternLarge-16 10000 109491 ns/op
BenchmarkHasLinkWithPatternAndDomainPatternLarge-16 (Now) 967 1291647 ns/op
BenchmarkHasLinkWithPatternAndDomainPatternLarge-16 62 23981366 ns/op
BenchmarkRBACModelWithDomainPatternLarge-16 (Now) 2552 467868 ns/op
BenchmarkRBACModelWithDomainPatternLarge-16 1200 1067164 ns/op

IssueHunt Summary

Referenced issues

This pull request has been submitted to:


@hsluoyz
Copy link
Member

hsluoyz commented May 24, 2021

@giefferre @closetool plz review.

@hsluoyz
Copy link
Member

hsluoyz commented May 24, 2021

@sagilio will perf: xxx have a new release? If not, plz use fix: xxx.

@sagilio sagilio changed the title perf: improve AddLink and KeyMatch4 performance fix: improve AddLink and KeyMatch4 performance May 24, 2021
@sagilio sagilio marked this pull request as draft May 24, 2021 17:50
@kilosonc
Copy link
Contributor

kilosonc commented May 25, 2021

@sagilio Please consider this one.

if rm.matchingFunc(namePattern, name1) {
	valueRole, _ := rm.roles.LoadOrStore(key.(string), newRole(key.(string)))
	valueRole.(*Role).addRole(role1)
}
if  rm.matchingFunc(name2, namePattern) {
	role2.addRole(value.(*Role))
}

@sagilio
Copy link
Contributor Author

sagilio commented May 25, 2021

@sagilio Please consider this one.

if rm.matchingFunc(namePattern, name1) {
	valueRole, _ := rm.roles.LoadOrStore(key.(string), newRole(key.(string)))
	valueRole.(*Role).addRole(role1)
}
if  rm.matchingFunc(name2, namePattern) {
	role2.addRole(value.(*Role))
}

Ok!

Copy link
Contributor

@kilosonc kilosonc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hsluoyz
Copy link
Member

hsluoyz commented May 26, 2021

@giefferre

@sagilio sagilio force-pushed the fix#781 branch 3 times, most recently from 3ac9243 to 0b19a9b Compare June 23, 2021 18:36
@sagilio sagilio force-pushed the fix#781 branch 10 times, most recently from 28f7a17 to ac47e4a Compare July 7, 2021 12:26
@sagilio sagilio changed the title fix: improve AddLink and KeyMatch4 performance fix: improve AddLink and HasLink with KeyMatch4 pattern performance Jul 7, 2021
Signed-off-by: Sagilio <Sagilio@outlook.com>
@sagilio sagilio marked this pull request as ready for review July 7, 2021 14:01
@hsluoyz hsluoyz merged commit e5ea4ae into apache:master Jul 8, 2021
@github-actions
Copy link

github-actions bot commented Jul 8, 2021

🎉 This PR is included in version 2.31.10 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

4 participants