-
Notifications
You must be signed in to change notification settings - Fork 3
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: speed-up policy evaluation #419
Conversation
Benchmark Results
|
We identified new issues on unchanged lines of code. Navigate to the Amazon CodeGuru Reviewer console to view the recommendations to fix them. |
Code Coverage Report
Minimum allowed coverage is Generated by 🐒 cobertura-action against 3d67e1f |
2 megaops/s seems good enough :) |
Operation op; | ||
try { | ||
op = parseOperation(request.getOperation()); | ||
} catch (PolicyException e) { | ||
logger.atError().setCause(e).log(); | ||
return false; | ||
} | ||
|
||
Resource rsc; | ||
try { | ||
rsc = parseResource(request.getResource()); | ||
} catch (PolicyException e) { | ||
logger.atError().setCause(e).log(); | ||
return false; | ||
} |
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.
nit: these two try can be combined.
@@ -119,6 +130,7 @@ private boolean compareOperation(Operation requestOperation, String policyOperat | |||
if (requestOperation.getOperationStr().equals(policyOperation)) { | |||
return true; | |||
} | |||
// TODO |
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.
todo?
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.
yeah to replace string formats, will take care of those now
src/main/java/com/aws/greengrass/clientdevices/auth/PermissionEvaluationUtils.java
Show resolved
Hide resolved
src/main/java/com/aws/greengrass/clientdevices/auth/PermissionEvaluationUtils.java
Show resolved
Hide resolved
throw new PolicyException(EXCEPTION_MALFORMED_RESOURCE); | ||
} | ||
|
||
String resourceName = typeAndName.substring(split + 1); |
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.
same here
* @param end substring end, | ||
* @return substring | ||
*/ | ||
private static String safeSubstring(@NonNull String str, int start, int end) { |
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.
nonnull will throw if it is null. Is that what you want?
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.
Is this really any safer or just not doing what you expect it to do. This seems more confusing to me than helpful IMO
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.
Maybe just needs a rename: "substringWhenInBounds" for example
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.
if it's more confusing doesn't seem worth it, will just add checking inline
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.
done, also added more tests
Issue #, if available:
Description of changes:
So far these changes provide roughly a ~2x speedup. Still using regex for the resource name to match, as emulating
Pattern.UNICODE_CHARACTER_CLASS
behavior looks to be very complicated, otherwise we would have gotten closer to a ~4x speedup on the benchmarks.Why is this change necessary:
How was this change tested:
Any additional information or context required to review the change:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.