Skip to content

feat: change PolicyMap from nomal map to sync.map (#1495)#1511

Closed
D0000M wants to merge 1 commit intoapache:masterfrom
D0000M:newfix
Closed

feat: change PolicyMap from nomal map to sync.map (#1495)#1511
D0000M wants to merge 1 commit intoapache:masterfrom
D0000M:newfix

Conversation

@D0000M
Copy link
Copy Markdown
Contributor

@D0000M D0000M commented Aug 4, 2025

feat: change PolicyMap from nomal map to sync.map (#1495), may have some help.

I couldn't reproduce the issue on my side, but I suspect it might be due to the lock granularity in SyncedEnforcer, or maybe some methods are being called inside a locked context and then call other functions that aren't aware of the lock.

My proposed solution is to change Assertion.PolicyMap from a map[string]int to a sync.Map, which seems to fix the problem. But it does have a noticeable impact on performance—overall benchmark performance drops by about 3%, and BenchmarkAddPolicy and BenchmarkRemovePolicy drop by 10–46%.

So it's really a trade-off.

@LarsArtmann
Copy link
Copy Markdown

Link/Related to: #1513

@hsluoyz hsluoyz closed this Nov 1, 2025
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.

3 participants