Skip to content

⚡ perf: optimize helpers performance#4049

Merged
ReneWerner87 merged 16 commits intomainfrom
performance_improvements
Feb 7, 2026
Merged

⚡ perf: optimize helpers performance#4049
ReneWerner87 merged 16 commits intomainfrom
performance_improvements

Conversation

@ReneWerner87
Copy link
Member

@ReneWerner87 ReneWerner87 commented Feb 4, 2026

Benchstat (base: origin/main, head: this branch)

  • Benchmark_Utils_GetSplicedStrList

    • 32.08ns -> 23.62ns (-26.37%, p=0.000)
  • Benchmark_Utils_IsNoCache

    • 100.70ns -> 29.79ns (-70.42%, p=0.000)
  • Benchmark_App_RebuildTree

    • 11.63µs -> 10.57µs (-9.14%, p=0.000)
  • Benchmark_FilterFlags

    • 10.59ns -> 10.08ns

@ReneWerner87 ReneWerner87 added the v3 label Feb 4, 2026
@coderabbitai

This comment was marked as outdated.

@ReneWerner87 ReneWerner87 added this to v3 Feb 4, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone Feb 4, 2026
@gemini-code-assist

This comment was marked as outdated.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces several performance optimizations aimed at reducing memory allocations, primarily by using sync.Pool for maps and stack-allocated arrays for slices. The changes are well-implemented and should provide a good performance boost in most cases. I've found one area in res.go where the optimization could lead to a performance regression under a specific configuration and have provided a suggestion to improve it. Overall, this is a solid contribution to improving the framework's performance.

github-actions[bot]

This comment was marked as spam.

@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

❌ Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.10%. Comparing base (4df2fce) to head (102126e).
⚠️ Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
helpers.go 92.59% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4049      +/-   ##
==========================================
+ Coverage   91.09%   91.10%   +0.01%     
==========================================
  Files         119      119              
  Lines       11184    11203      +19     
==========================================
+ Hits        10188    10207      +19     
  Misses        630      630              
  Partials      366      366              
Flag Coverage Δ
unittests 91.10% <94.44%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@ReneWerner87 ReneWerner87 changed the title perf: optimize memory allocation in binders using sync.Pool and stack-allocated arrays perf: optimize performance Feb 6, 2026
@ReneWerner87 ReneWerner87 marked this pull request as ready for review February 6, 2026 07:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements several targeted performance optimizations that collectively reduce execution time and memory allocations across critical code paths. The changes focus on eliminating unnecessary UTF-8 decoding in string operations, reusing slice capacity to reduce allocations, and optimizing case-insensitive string matching. Benchmark results show significant improvements: 26% faster string splitting, 70% faster cache directive detection, and 9% faster route tree rebuilding.

Changes:

  • Optimized string iteration by replacing range loops with index-based byte access when only ASCII matching is needed
  • Implemented slice capacity reuse in route tree rebuilding to reduce allocations
  • Refactored cache directive parsing with inline case-folding and extracted helper functions for better performance

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
router.go Added reuseRouteBucket function to reuse slice capacity when rebuilding route trees, reducing allocations in buildTree
helpers.go Optimized getSplicedStrList with index-based loop and refactored isNoCache with inline case-folding, added tab as valid delimiter
binder/mapping.go Optimized FilterFlags by replacing range loop with strings.IndexAny
binder/mapping_test.go Added benchmark test for FilterFlags to track performance

@arlanram
Copy link

arlanram commented Feb 6, 2026

this pr almost have no necessary performance improvements

@ReneWerner87
Copy link
Member Author

this pr almost have no necessary performance improvements

Thanks for the assessment.
Two of the functions have been significantly optimized and two have been only slightly optimized.
Every performance improvement helps.

If you have any changes that significantly improve performance, please feel free to create a pull request.

@gaby gaby changed the title perf: optimize performance ⚡ perrf: optimize helpers performance Feb 7, 2026
@gaby gaby changed the title ⚡ perrf: optimize helpers performance ⚡ perf: optimize helpers performance Feb 7, 2026
Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

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

LGTM

@ReneWerner87 ReneWerner87 merged commit 8b5d061 into main Feb 7, 2026
28 of 30 checks passed
@ReneWerner87 ReneWerner87 deleted the performance_improvements branch February 7, 2026 07:22
@github-project-automation github-project-automation bot moved this to Done in v3 Feb 7, 2026
@ReneWerner87 ReneWerner87 modified the milestones: v3, v3.1.0 Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants