Optimize uniq function for better performance - #852
Merged
Conversation
Improve the performance of the unique function by: 1. Pre-allocating map capacity with len(s) to avoid frequent map resizing 2. Pre-allocating result slice capacity with len(s) to reduce append overhead 3. Reducing the number of traversals performs well under the condition of a large number of elements These changes maintain the original behavior (preserving element order) while reducing memory allocation operations, especially effective for large slices (100k+ elements) with benchmark showing ~25% speedup. No breaking changes, the function signature and output order remain unchanged.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #852 +/- ##
==========================================
- Coverage 78.77% 78.76% -0.01%
==========================================
Files 56 56
Lines 2671 2670 -1
==========================================
- Hits 2104 2103 -1
Misses 476 476
Partials 91 91 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
eternal-flame-AD
approved these changes
Oct 2, 2025
eternal-flame-AD
left a comment
Member
There was a problem hiding this comment.
Hi, thanks for the PR, currently this code is ran very infrequently (every a couple minutes) and input size is constrained by the # of open connections your system can take, so I doubt this is going to be the bottleneck on application performance.
But otherwise lgtm
Contributor
Author
|
Thanks for your review! I understand your point about the execution frequency and input size. Just wanted to optimize it as a precautionary measure. Glad you think it looks good otherwise. Let me know if there's anything else needed.
…---- 回复的原邮件 ----
| 发件人 | 饺子w ***@***.***> |
| 日期 | 2025年10月02日 13:15 |
| 收件人 | ***@***.***> |
| 抄送至 | ***@***.***>***@***.***> |
| 主题 | Re: [gotify/server] Optimize uniq function for better performance (PR #852) |
@eternal-flame-AD approved this pull request.
Hi, thanks for the PR, currently this code is ran very infrequently (every a couple minutes) and input size is constrained by the # of open connections your system can take, so I doubt this is going to be the bottleneck on application performance.
But otherwise lgtm
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improve the performance of the unique function by:
These changes maintain the original behavior (preserving element order) while reducing memory allocation operations, especially effective for large slices (100k+ elements) with benchmark showing ~25% speedup.
No breaking changes, the function signature and output order remain unchanged.