Skip to content

Optimize uniq function for better performance - #852

Merged
eternal-flame-AD merged 1 commit into
gotify:masterfrom
Ben1524:perf_uniq_func
Oct 3, 2025
Merged

Optimize uniq function for better performance#852
eternal-flame-AD merged 1 commit into
gotify:masterfrom
Ben1524:perf_uniq_func

Conversation

@Ben1524

@Ben1524 Ben1524 commented Oct 1, 2025

Copy link
Copy Markdown
Contributor

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.

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.
@Ben1524
Ben1524 requested a review from a team as a code owner October 1, 2025 16:07
@codecov

codecov Bot commented Oct 2, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.76%. Comparing base (f77d404) to head (0af2fed).
⚠️ Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@eternal-flame-AD eternal-flame-AD left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@Ben1524

Ben1524 commented Oct 2, 2025 via email

Copy link
Copy Markdown
Contributor Author

@eternal-flame-AD
eternal-flame-AD merged commit 4bc42d2 into gotify:master Oct 3, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants