casbin / casbin-rs

An authorization library that supports access control models like ACL, RBAC, ABAC in Rust.
https://casbin.org
Apache License 2.0
828 stars 67 forks source link

feat: replace lru with mini-moka for caching #307

Closed kbalt closed 1 year ago

kbalt commented 1 year ago

Replace the lru library with mini-moka for caching. This allows the API to take &self instead of &mut self for most operations.

This also allows to only take a read lock when executing g functions.

github-actions[bot] commented 1 year ago

Benchmark for e161068

Click to view benchmark | Test | PR Benchmark | Master Benchmark | % | |------|--------------|------------------|---| | b_benchmark_rbac_model_large | **12.3±0.01ms** | 15.6±0.48ms | **-21.15%** | | benchmark priority model | 6.5±0.02µs | 6.5±0.01µs | 0.00% | | benchmark_abac_model | 3.7±0.01µs | 3.7±0.01µs | 0.00% | | benchmark_basic_model | 5.8±0.04µs | **5.6±0.01µs** | **+3.57%** | | benchmark_key_match | 19.5±0.12µs | 19.6±0.79µs | -0.51% | | benchmark_raw | 3.5±0.05ns | **3.2±0.00ns** | **+9.38%** | | benchmark_rbac_model | **9.2±0.02µs** | 9.8±0.02µs | **-6.12%** | | benchmark_rbac_model_medium | **1164.6±0.96µs** | 1452.9±17.52µs | **-19.84%** | | benchmark_rbac_model_with_domains | **9.0±0.02µs** | 9.5±0.01µs | **-5.26%** | | benchmark_rbac_with_deny | **11.8±0.02µs** | 13.3±0.08µs | **-11.28%** | | benchmark_rbac_with_resource_roles | **6.7±0.02µs** | 6.8±0.02µs | **-1.47%** | | benchmark_role_manager_large | **4.9±0.02ms** | 6.8±0.06ms | **-27.94%** | | benchmark_role_manager_medium | **413.6±0.45µs** | 612.3±0.90µs | **-32.45%** | | benchmark_role_manager_small | **118.5±0.25µs** | 146.4±2.38µs | **-19.06%** |
hackerchai commented 1 year ago

@kbalt plz fix the CI errors

github-actions[bot] commented 1 year ago

Benchmark for e161068

Click to view benchmark | Test | PR Benchmark | Master Benchmark | % | |------|--------------|------------------|---| | b_benchmark_rbac_model_large | **13.5±0.37ms** | 15.6±0.81ms | **-13.46%** | | benchmark priority model | **7.1±0.24µs** | 7.5±0.17µs | **-5.33%** | | benchmark_abac_model | **4.0±0.15µs** | 4.3±0.06µs | **-6.98%** | | benchmark_basic_model | 6.3±0.13µs | **6.1±0.18µs** | **+3.28%** | | benchmark_key_match | **21.0±0.65µs** | 22.4±0.38µs | **-6.25%** | | benchmark_raw | 4.7±0.07ns | **4.5±0.17ns** | **+4.44%** | | benchmark_rbac_model | 10.5±0.13µs | **10.3±0.36µs** | **+1.94%** | | benchmark_rbac_model_medium | **1245.8±33.70µs** | 1469.2±30.06µs | **-15.21%** | | benchmark_rbac_model_with_domains | **10.1±0.36µs** | 10.5±0.18µs | **-3.81%** | | benchmark_rbac_with_deny | **13.6±0.44µs** | 14.0±0.20µs | **-2.86%** | | benchmark_rbac_with_resource_roles | **7.5±0.32µs** | 7.9±0.11µs | **-5.06%** | | benchmark_role_manager_large | **5.3±0.18ms** | 6.1±0.20ms | **-13.11%** | | benchmark_role_manager_medium | **454.5±11.78µs** | 540.6±16.09µs | **-15.93%** | | benchmark_role_manager_small | **129.2±3.35µs** | 147.6±4.76µs | **-12.47%** |
github-actions[bot] commented 1 year ago

Benchmark for e161068

Click to view benchmark | Test | PR Benchmark | Master Benchmark | % | |------|--------------|------------------|---| | b_benchmark_rbac_model_large | **12.3±0.01ms** | 14.5±0.25ms | **-15.17%** | | benchmark priority model | **6.5±0.01µs** | 6.7±0.01µs | **-2.99%** | | benchmark_abac_model | 3.8±0.01µs | **3.6±0.01µs** | **+5.56%** | | benchmark_basic_model | **5.7±0.01µs** | 5.9±0.01µs | **-3.39%** | | benchmark_key_match | **19.4±0.16µs** | 19.5±0.06µs | **-0.51%** | | benchmark_raw | 3.2±0.01ns | 3.2±0.01ns | 0.00% | | benchmark_rbac_model | **9.1±0.01µs** | 9.6±0.02µs | **-5.21%** | | benchmark_rbac_model_medium | **1170.5±30.63µs** | 1367.5±0.90µs | **-14.41%** | | benchmark_rbac_model_with_domains | 9.4±0.01µs | **9.2±0.26µs** | **+2.17%** | | benchmark_rbac_with_deny | **12.5±0.02µs** | 13.2±0.02µs | **-5.30%** | | benchmark_rbac_with_resource_roles | 7.0±0.01µs | 7.0±0.01µs | 0.00% | | benchmark_role_manager_large | **4.9±0.00ms** | 5.9±0.00ms | **-16.95%** | | benchmark_role_manager_medium | **411.2±0.75µs** | 518.2±1.48µs | **-20.65%** | | benchmark_role_manager_small | **118.8±0.24µs** | 143.7±0.17µs | **-17.33%** |
github-actions[bot] commented 1 year ago

Benchmark for e161068

Click to view benchmark | Test | PR Benchmark | Master Benchmark | % | |------|--------------|------------------|---| | b_benchmark_rbac_model_large | 12.6±0.69ms | 12.9±0.81ms | -2.33% | | benchmark priority model | 6.6±0.44µs | 6.4±0.43µs | +3.12% | | benchmark_abac_model | 3.5±0.18µs | 3.6±0.21µs | -2.78% | | benchmark_basic_model | 5.5±0.25µs | **5.2±0.25µs** | **+5.77%** | | benchmark_key_match | 23.0±1.22µs | 22.2±1.14µs | +3.60% | | benchmark_raw | 3.7±0.17ns | 3.8±0.21ns | -2.63% | | benchmark_rbac_model | 8.9±0.56µs | 8.8±0.46µs | +1.14% | | benchmark_rbac_model_medium | **1138.1±65.04µs** | 1224.6±61.41µs | **-7.06%** | | benchmark_rbac_model_with_domains | 9.1±0.56µs | 9.1±0.59µs | 0.00% | | benchmark_rbac_with_deny | 11.5±0.71µs | 11.5±0.54µs | 0.00% | | benchmark_rbac_with_resource_roles | 6.6±0.38µs | 6.6±0.43µs | 0.00% | | benchmark_role_manager_large | 6.9±0.31ms | **5.8±0.44ms** | **+18.97%** | | benchmark_role_manager_medium | **422.7±24.97µs** | 499.3±25.34µs | **-15.34%** | | benchmark_role_manager_small | **117.5±7.54µs** | 123.4±5.56µs | **-4.78%** |
github-actions[bot] commented 1 year ago

Benchmark for e161068

Click to view benchmark | Test | PR Benchmark | Master Benchmark | % | |------|--------------|------------------|---| | b_benchmark_rbac_model_large | **12.1±0.03ms** | 12.6±0.06ms | **-3.97%** | | benchmark priority model | 6.4±0.01µs | 6.4±0.01µs | 0.00% | | benchmark_abac_model | 3.6±0.02µs | **3.4±0.01µs** | **+5.88%** | | benchmark_basic_model | 5.4±0.01µs | 5.4±0.01µs | 0.00% | | benchmark_key_match | 19.4±0.05µs | 19.4±0.03µs | 0.00% | | benchmark_raw | **4.0±0.01ns** | 4.7±0.05ns | **-14.89%** | | benchmark_rbac_model | 9.0±0.01µs | **8.7±0.01µs** | **+3.45%** | | benchmark_rbac_model_medium | **1120.4±2.75µs** | 1183.1±2.48µs | **-5.30%** | | benchmark_rbac_model_with_domains | 9.2±0.02µs | **8.8±0.01µs** | **+4.55%** | | benchmark_rbac_with_deny | 12.2±0.01µs | **12.0±0.01µs** | **+1.67%** | | benchmark_rbac_with_resource_roles | 6.7±0.02µs | **6.6±0.01µs** | **+1.52%** | | benchmark_role_manager_large | **4.7±0.00ms** | 5.5±0.00ms | **-14.55%** | | benchmark_role_manager_medium | **405.2±0.19µs** | 496.5±4.09µs | **-18.39%** | | benchmark_role_manager_small | **113.9±0.18µs** | 124.5±0.10µs | **-8.51%** |
github-actions[bot] commented 1 year ago

Benchmark for e161068

Click to view benchmark | Test | PR Benchmark | Master Benchmark | % | |------|--------------|------------------|---| | b_benchmark_rbac_model_large | 17.1±0.82ms | 16.7±1.04ms | +2.40% | | benchmark priority model | 7.5±0.25µs | 7.7±0.41µs | -2.60% | | benchmark_abac_model | 4.5±0.33µs | **4.2±0.14µs** | **+7.14%** | | benchmark_basic_model | 6.5±0.78µs | 6.8±0.57µs | -4.41% | | benchmark_key_match | 27.1±1.54µs | 27.1±1.53µs | 0.00% | | benchmark_raw | 4.5±0.31ns | 4.7±0.22ns | -4.26% | | benchmark_rbac_model | 10.4±1.04µs | 10.7±0.41µs | -2.80% | | benchmark_rbac_model_medium | **1354.7±89.49µs** | 1512.6±36.88µs | **-10.44%** | | benchmark_rbac_model_with_domains | 10.8±0.54µs | 10.8±0.49µs | 0.00% | | benchmark_rbac_with_deny | 14.5±0.42µs | 14.3±1.02µs | +1.40% | | benchmark_rbac_with_resource_roles | 7.8±0.52µs | 8.0±0.31µs | -2.50% | | benchmark_role_manager_large | 6.6±0.45ms | 6.9±0.43ms | -4.35% | | benchmark_role_manager_medium | **504.1±22.53µs** | 614.9±21.32µs | **-18.02%** | | benchmark_role_manager_small | **140.1±7.64µs** | 150.3±7.18µs | **-6.79%** |
hsluoyz commented 1 year ago

@kbalt plz fix: https://github.com/casbin/casbin-rs/actions/runs/4699340306/jobs/8332688165?pr=307

image

codecov[bot] commented 1 year ago

Codecov Report

Merging #307 (f9dd3f6) into master (e161068) will decrease coverage by 14.12%. The diff coverage is 78.94%.

@@             Coverage Diff             @@
##           master     #307       +/-   ##
===========================================
- Coverage   81.46%   67.34%   -14.12%     
===========================================
  Files          23       24        +1     
  Lines        3463     1779     -1684     
===========================================
- Hits         2821     1198     -1623     
+ Misses        642      581       -61     
Impacted Files Coverage Δ
src/cached_enforcer.rs 0.00% <0.00%> (-4.17%) :arrow_down:
src/convert.rs 57.14% <ø> (+11.98%) :arrow_up:
src/enforcer.rs 70.53% <ø> (-16.72%) :arrow_down:
src/adapter/file_adapter.rs 62.50% <100.00%> (+1.04%) :arrow_up:
src/cache/default_cache.rs 100.00% <100.00%> (+2.94%) :arrow_up:
src/macros.rs 50.00% <100.00%> (ø)
src/rbac/default_role_manager.rs 95.21% <100.00%> (-2.22%) :arrow_down:

... and 10 files with indirect coverage changes

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

github-actions[bot] commented 1 year ago

Benchmark for e161068

Click to view benchmark | Test | PR Benchmark | Master Benchmark | % | |------|--------------|------------------|---| | b_benchmark_rbac_model_large | **12.1±0.03ms** | 12.6±0.08ms | **-3.97%** | | benchmark priority model | 6.4±0.02µs | **6.3±0.01µs** | **+1.59%** | | benchmark_abac_model | 3.6±0.01µs | **3.5±0.01µs** | **+2.86%** | | benchmark_basic_model | 5.5±0.01µs | **5.4±0.01µs** | **+1.85%** | | benchmark_key_match | 19.4±0.03µs | **19.2±0.03µs** | **+1.04%** | | benchmark_raw | 4.0±0.00ns | 4.0±0.03ns | 0.00% | | benchmark_rbac_model | 9.0±0.02µs | **8.6±0.01µs** | **+4.65%** | | benchmark_rbac_model_medium | **1099.1±1.09µs** | 1187.0±8.53µs | **-7.41%** | | benchmark_rbac_model_with_domains | 9.1±0.01µs | **8.9±0.01µs** | **+2.25%** | | benchmark_rbac_with_deny | 12.1±0.02µs | **12.0±0.01µs** | **+0.83%** | | benchmark_rbac_with_resource_roles | **6.6±0.01µs** | 6.7±0.01µs | **-1.49%** | | benchmark_role_manager_large | **4.8±0.02ms** | 5.4±0.01ms | **-11.11%** | | benchmark_role_manager_medium | **409.5±0.22µs** | 484.9±0.32µs | **-15.55%** | | benchmark_role_manager_small | **113.6±0.06µs** | 123.3±0.16µs | **-7.87%** |
github-actions[bot] commented 1 year ago

Benchmark for e161068

Click to view benchmark | Test | PR Benchmark | Master Benchmark | % | |------|--------------|------------------|---| | b_benchmark_rbac_model_large | **12.3±0.02ms** | 14.3±0.36ms | **-13.99%** | | benchmark priority model | 6.7±0.02µs | **6.5±0.01µs** | **+3.08%** | | benchmark_abac_model | 3.8±0.02µs | **3.7±0.12µs** | **+2.70%** | | benchmark_basic_model | 5.7±0.03µs | 5.7±0.03µs | 0.00% | | benchmark_key_match | 19.7±0.05µs | **19.3±0.05µs** | **+2.07%** | | benchmark_raw | 3.2±0.00ns | 3.2±0.15ns | 0.00% | | benchmark_rbac_model | 9.3±0.03µs | **9.0±0.02µs** | **+3.33%** | | benchmark_rbac_model_medium | **1168.4±12.33µs** | 1271.9±1.49µs | **-8.14%** | | benchmark_rbac_model_with_domains | 9.4±0.02µs | **9.1±0.01µs** | **+3.30%** | | benchmark_rbac_with_deny | 12.7±0.05µs | 12.7±0.36µs | 0.00% | | benchmark_rbac_with_resource_roles | 7.0±0.02µs | **6.8±0.02µs** | **+2.94%** | | benchmark_role_manager_large | **4.9±0.00ms** | 5.9±0.26ms | **-16.95%** | | benchmark_role_manager_medium | **413.7±0.58µs** | 517.1±0.59µs | **-20.00%** | | benchmark_role_manager_small | **121.6±0.08µs** | 132.8±0.10µs | **-8.43%** |
github-actions[bot] commented 1 year ago

Benchmark for e161068

Click to view benchmark | Test | PR Benchmark | Master Benchmark | % | |------|--------------|------------------|---| | b_benchmark_rbac_model_large | 18.4±0.80ms | **17.4±1.12ms** | **+5.75%** | | benchmark priority model | 8.1±0.93µs | 7.9±0.45µs | +2.53% | | benchmark_abac_model | 4.6±0.26µs | 4.4±0.21µs | +4.55% | | benchmark_basic_model | 7.0±0.36µs | 7.2±0.40µs | -2.78% | | benchmark_key_match | 28.7±1.40µs | 28.4±1.19µs | +1.06% | | benchmark_raw | 4.8±0.21ns | 5.0±0.24ns | -4.00% | | benchmark_rbac_model | 11.6±0.47µs | 11.9±0.57µs | -2.52% | | benchmark_rbac_model_medium | **1518.3±74.73µs** | 1628.3±75.16µs | **-6.76%** | | benchmark_rbac_model_with_domains | 11.6±0.63µs | 11.3±0.58µs | +2.65% | | benchmark_rbac_with_deny | 15.5±0.74µs | 15.5±0.91µs | 0.00% | | benchmark_rbac_with_resource_roles | 8.4±0.60µs | 8.6±0.51µs | -2.33% | | benchmark_role_manager_large | 7.4±0.27ms | 7.2±0.43ms | +2.78% | | benchmark_role_manager_medium | **590.5±29.85µs** | 640.9±36.28µs | **-7.86%** | | benchmark_role_manager_small | 156.7±7.64µs | 162.6±6.70µs | -3.63% |
github-actions[bot] commented 1 year ago

Benchmark for e161068

Click to view benchmark | Test | PR Benchmark | Master Benchmark | % | |------|--------------|------------------|---| | b_benchmark_rbac_model_large | **16.4±0.61ms** | 17.3±1.15ms | **-5.20%** | | benchmark priority model | 8.0±0.29µs | 8.0±0.42µs | 0.00% | | benchmark_abac_model | 4.4±0.18µs | 4.4±0.24µs | 0.00% | | benchmark_basic_model | 7.1±0.68µs | **6.8±0.24µs** | **+4.41%** | | benchmark_key_match | 27.9±1.05µs | 28.0±1.54µs | -0.36% | | benchmark_raw | 4.9±0.19ns | 4.8±0.19ns | +2.08% | | benchmark_rbac_model | 11.2±1.01µs | 10.9±0.45µs | +2.75% | | benchmark_rbac_model_medium | **1413.3±69.51µs** | 1590.2±69.50µs | **-11.12%** | | benchmark_rbac_model_with_domains | 11.3±0.36µs | 11.2±0.63µs | +0.89% | | benchmark_rbac_with_deny | **14.7±0.44µs** | 15.2±0.77µs | **-3.29%** | | benchmark_rbac_with_resource_roles | 8.3±0.35µs | 8.4±0.31µs | -1.19% | | benchmark_role_manager_large | 8.7±0.33ms | **7.0±0.46ms** | **+24.29%** | | benchmark_role_manager_medium | **531.3±26.36µs** | 638.3±28.76µs | **-16.76%** | | benchmark_role_manager_small | **145.8±5.09µs** | 160.0±8.22µs | **-8.88%** |
hsluoyz commented 1 year ago

@kbalt plz fix:

image

kbalt commented 1 year ago

Code coverage is complaining about a huge coverage regression in src/enforcer.rs when I just added one single line in there. The rest should be resolved now.

github-actions[bot] commented 1 year ago

Benchmark for e161068

Click to view benchmark | Test | PR Benchmark | Master Benchmark | % | |------|--------------|------------------|---| | b_benchmark_rbac_model_large | **11.8±0.06ms** | 13.6±0.60ms | **-13.24%** | | benchmark priority model | 6.5±0.01µs | **6.4±0.02µs** | **+1.56%** | | benchmark_abac_model | 3.5±0.01µs | 3.5±0.03µs | 0.00% | | benchmark_basic_model | 5.5±0.00µs | **5.4±0.01µs** | **+1.85%** | | benchmark_key_match | 19.6±0.03µs | **19.5±0.03µs** | **+0.51%** | | benchmark_raw | 4.0±0.00ns | 4.0±0.00ns | 0.00% | | benchmark_rbac_model | 9.0±0.03µs | **8.5±0.01µs** | **+5.88%** | | benchmark_rbac_model_medium | **1114.4±5.64µs** | 1186.6±2.57µs | **-6.08%** | | benchmark_rbac_model_with_domains | 9.1±0.01µs | **8.8±0.04µs** | **+3.41%** | | benchmark_rbac_with_deny | **11.7±0.02µs** | 11.9±0.01µs | **-1.68%** | | benchmark_rbac_with_resource_roles | 6.6±0.01µs | 6.6±0.01µs | 0.00% | | benchmark_role_manager_large | **4.8±0.06ms** | 5.4±0.03ms | **-11.11%** | | benchmark_role_manager_medium | **407.8±0.51µs** | 484.3±0.32µs | **-15.80%** | | benchmark_role_manager_small | **114.9±0.43µs** | 123.4±0.08µs | **-6.89%** |