Skip to content

refactor: optimize speed#4231

Merged
ReneWerner87 merged 3 commits into
mainfrom
optimize-performance
Apr 25, 2026
Merged

refactor: optimize speed#4231
ReneWerner87 merged 3 commits into
mainfrom
optimize-performance

Conversation

@ReneWerner87

@ReneWerner87 ReneWerner87 commented Apr 24, 2026

Copy link
Copy Markdown
Member

This PR applies small, benchmark-backed optimizations in Fiber core paths:

  • Simplifies parameterized route matching by returning routeParser.getMatch(...) directly.
  • Optimizes Ctx.BaseURL() string construction with an exactly sized byte buffer.
  • Optimizes Ctx.String() by writing the 16-byte hex request ID directly instead of using strconv.FormatUint.
  • Updates the spell-check workflow Node.js version to 24.

Performance

Benchmarked with go test -bench ... -benchmem -count=20 and compared with benchstat.

Benchmark Before After Change
Benchmark_Router_Handler 87.98 ns/op 84.44 ns/op -4.03%
Benchmark_Route_Match 13.20 ns/op 13.06 ns/op -1.06%
Benchmark_Ctx_BaseURL_Uncached 47.99 ns/op 39.48 ns/op -17.72%
Benchmark_Ctx_BaseURL 2.054 ns/op 1.962 ns/op -4.50%
Benchmark_Ctx_String 192.3 ns/op 171.6 ns/op -10.79%

No allocation regressions were observed in these benchmarks.

Copilot AI review requested due to automatic review settings April 24, 2026 15:19
@ReneWerner87 ReneWerner87 requested a review from a team as a code owner April 24, 2026 15:19
@coderabbitai

coderabbitai Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 146b8317-e547-49f3-87fa-2d843f67f3bc

📥 Commits

Reviewing files that changed from the base of the PR and between c3980c0 and 993175d.

📒 Files selected for processing (1)
  • ctx_test.go

Walkthrough

Simplifies route matching return path; optimizes context BaseURL and context ID string construction with byte-level encoding and removes strconv; adds two benchmarks for uncached BaseURL() and FullURL().

Changes

Cohort / File(s) Summary
Router match
router.go
Simplified (*Route).match to return r.routeParser.getMatch(...) directly, removing a redundant conditional branch.
Context string/URL optimizations
ctx.go
Rewrote BaseURL() to build scheme://host with a preallocated byte slice and c.app.toString; replaced String() ID formatting with direct 16-byte lowercase hex nibble encoding; removed strconv usage.
Context benchmarks
ctx_test.go
Added Benchmark_Ctx_BaseURL_Uncached and Benchmark_Ctx_FullURL to measure uncached BaseURL construction and FullURL allocations/performance.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • sixcolors
  • efectn

Poem

🐇 I hop through bytes and nibble lines of code,
I stitch a URL where schemes and hosts abode,
I trim a branch, make matching neat and lean,
Benchmarks patter—quick, precise, and keen,
A rabbit's cheer for lean and spry code-mode.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided, making it impossible to verify compliance with the repository's comprehensive description template that requires details on changes, benchmarks, documentation, and testing. Add a detailed description covering the changes introduced, performance improvements with benchmarks, any documentation updates, and confirmation that tests have been added and pass.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and generic, using non-descriptive terms like 'optimize speed' without indicating which components or methods are being optimized. Consider a more specific title such as 'refactor: optimize BaseURL and context ID string generation' that clearly indicates what is being optimized.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch optimize-performance

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.11.4)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors the route matching fast-path to reduce branching overhead when matching parameterized routes, improving router hot-path performance.

Changes:

  • Simplified parameterized route matching to directly return routeParser.getMatch(...) result.

@codecov

codecov Bot commented Apr 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.11%. Comparing base (771b689) to head (993175d).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4231      +/-   ##
==========================================
- Coverage   91.17%   91.11%   -0.07%     
==========================================
  Files         123      123              
  Lines       12076    12084       +8     
==========================================
  Hits        11010    11010              
- Misses        668      674       +6     
- Partials      398      400       +2     
Flag Coverage Δ
unittests 91.11% <100.00%> (-0.07%) ⬇️

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.

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

Copy link
Copy Markdown
Contributor

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 simplifies the parameter matching logic in router.go by directly returning the boolean result of the route parser's match function instead of using an explicit if statement. I have no feedback to provide as no review comments were submitted.

Comment thread ctx.go
@ReneWerner87 ReneWerner87 merged commit 49d4a78 into main Apr 25, 2026
23 checks passed
@ReneWerner87 ReneWerner87 deleted the optimize-performance branch April 25, 2026 10:41
@ReneWerner87 ReneWerner87 added this to the v3 milestone Apr 25, 2026
@ReneWerner87 ReneWerner87 added this to v3 Apr 25, 2026
@github-project-automation github-project-automation Bot moved this to Done in v3 Apr 25, 2026
@ReneWerner87 ReneWerner87 modified the milestones: v3, v3.2.0 Apr 25, 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