-
Notifications
You must be signed in to change notification settings - Fork 14
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(utils): improve the performance of scoring and reporting #212
Conversation
Could you add the new logic the the benchmark tests please. |
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.
Looks good!
One thing would be good to add is the new benchmark like here: #137
@BioPhoton @matejchalk well, it looks like the changes don't affect the performance in a positive way - I added the updated functions to the benchmark, file |
could we get the traces for that? |
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.
A have a question about the benchmarks. What numbers of audits and groups are you using?
The fact that imperative code is faster the declarative is not surprising (that's always the case in benchmarks which use extreme values), but the trick is figuring out if it's relevant to us or not.
If the performance optimizations are not noticeable for realistic amounts of data, then optimizing for code maintenance is still the way to go. E.g. if it doesn't make a difference until we reach thousands of groups, then it's not relevant to us, because that's not a realistic scenario and we would do better to prioritize our ability to understand and maintain the code and prevent bugs (side-effects like mutations are an anthesis to this). There's a famous quote that "premature optimization is the root of all evil", after all.
I would estimate that 100s and in extreme cases 1000s of audits are realistic (e.g. for the CLI, our very strict ESLint gives us 347 audits). So if the performance optimization has an impact at this level, then it's worth it, but if we don't see the performance benefits until we reach a million audits for example, then it isn't.
For groups, the number is much lower. I can't imagine we'd have over a 100 even.
Improved the performance of scoring and reporting.
Removed nested loops where possible, added dictionaries to go constant time O(1) instead of linear O(n).
Made minor refactoring, added some checks.
@BioPhoton As task owner, let me know if I understood the task correctly and implemented everything properly. Also, maybe you could propose additional changes for further performance improvements.
Closes #132