Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: Reduce allocations and printfs in G-function cache. (#958)
Previously, the G-function cache used repeated fmt.Sprintf("%v", x) and string concatenation to generate its cache key. This resulted in lots of unnecessary allocations, both in the process of Sprintf and in an O(n²) string building loop. This change allocates a string buffer and copies strings into it to reduce the number of allocations. This solution was found to be faster than using a composite map key (like a struct {string, string, string, int}). Includes minor ancillary changes: - Replaces `;` as the separator with a null character, making the cache safe for any string without nulls (i.e. your role could contain `;`, if you were the type of person who wanted to do that). - Adds a parameterized RBAC benchmark, with longer role names, to better see performance results in situations where clients have longer strings that might require more allocations.
- Loading branch information
1 parent
8dd3259
commit a6cd905
Showing
2 changed files
with
89 additions
and
8 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