Skip to content

🧹 chore: Add Immutable benchmarks for default case #3374

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

Merged
merged 1 commit into from
Mar 26, 2025

Conversation

gaby
Copy link
Member

@gaby gaby commented Mar 26, 2025

Description

Add two benchmarks to cover the most basic use-case with Immutable flag enabled

How to run:

go test -v ./... -run=^$ -bench=Benchmark_Router_Next_Default -benchmem -count=4

Related #3367

Changes introduced

List the new features or adjustments introduced in this pull request. Provide details on benchmarks, documentation updates, changelog entries, and if applicable, the migration guide.

  • Benchmarks: Describe any performance benchmarks and improvements related to the changes.

Type of change

  • Code consistency (non-breaking change which improves code reliability and robustness)

@gaby gaby added this to the v3 milestone Mar 26, 2025
@gaby gaby requested a review from a team as a code owner March 26, 2025 11:35
@gaby gaby added this to v3 Mar 26, 2025
@gaby gaby requested review from sixcolors, ReneWerner87 and efectn and removed request for a team March 26, 2025 11:35
Copy link
Contributor

coderabbitai bot commented Mar 26, 2025

Walkthrough

This pull request adds two benchmark functions in router_test.go that test the router's performance when using the Immutable configuration. The first benchmark, Benchmark_Router_Next_Default_Immutable, executes the GET route in a sequential loop, while the second, Benchmark_Router_Next_Default_Parallel_Immutable, runs the same logic concurrently using b.RunParallel. Both benchmarks simulate GET requests using a fasthttp.RequestCtx object.

Changes

File Change Summary
router_test.go Added Benchmark_Router_Next_Default_Immutable for sequential benchmarking and Benchmark_Router_Next_Default_Parallel_Immutable for parallel benchmarking of a GET route with Immutable config.

Sequence Diagram(s)

sequenceDiagram
    participant B as Benchmark
    participant A as App (Immutable)
    participant R as Route Handler
    participant C as RequestCtx

    B->>A: Create app with Immutable config
    A->>R: Register GET "/" route
    loop For each iteration
        B->>C: Initialize RequestCtx for GET "/"
        C->>R: Execute route handler
        R-->>C: Return response (nil)
    end
Loading
sequenceDiagram
    participant BP as Benchmark Parallel Runner
    participant A as App (Immutable)
    participant R as Route Handler
    participant C as RequestCtx (Per Goroutine)

    BP->>A: Create app with Immutable config
    A->>R: Register GET "/" route
    Note over BP,C: RunParallel spawns multiple goroutines
    loop Concurrent iterations
        BP->>C: Initialize RequestCtx for GET "/"
        C->>R: Execute route handler
        R-->>C: Return response (nil)
    end
Loading

Possibly related PRs

Suggested reviewers

  • sixcolors
  • efectn
  • ReneWerner87

Poem

Hopping through the code with cheer,
Benchmarks bloom as routes appear,
Immutable trails, both slow and fast,
Sequential and parallel run steadfast.
I, the coding rabbit, hop with delight,
Celebrating each test under moonlight!
🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4bf2929 and 87d51a6.

📒 Files selected for processing (1)
  • router_test.go (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
router_test.go (4)
app.go (2)
  • Config (135-411)
  • Handler (38-38)
internal/storage/memory/config.go (1)
  • Config (8-13)
ctx_interface_gen.go (1)
  • Ctx (17-365)
constants.go (1)
  • MethodGet (5-5)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: unit (1.24.x, macos-latest)
  • GitHub Check: Compare
  • GitHub Check: unit (1.24.x, macos-13)
  • GitHub Check: unit (1.23.x, macos-13)
  • GitHub Check: unit (1.24.x, windows-latest)
  • GitHub Check: unit (1.23.x, windows-latest)
  • GitHub Check: repeated
🔇 Additional comments (2)
router_test.go (2)

659-678: LGTM! Well-structured benchmark for the Immutable configuration.

The benchmark follows the same pattern as the existing Benchmark_Router_Next_Default function but with the Immutable flag set to true. It correctly reports allocations and resets the timer before executing the benchmark loop.


680-701: LGTM! Properly implemented parallel benchmark for the Immutable configuration.

This parallel benchmark matches the pattern of the existing Benchmark_Router_Next_Default_Parallel function but with the Immutable flag enabled. The implementation correctly creates a new context for each goroutine and runs the benchmarks concurrently.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Mar 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.73%. Comparing base (4bf2929) to head (87d51a6).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3374      +/-   ##
==========================================
+ Coverage   83.67%   83.73%   +0.06%     
==========================================
  Files         118      118              
  Lines       11721    11721              
==========================================
+ Hits         9807     9815       +8     
+ Misses       1486     1480       -6     
+ Partials      428      426       -2     
Flag Coverage Δ
unittests 83.73% <ø> (+0.06%) ⬆️

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.

@gaby
Copy link
Member Author

gaby commented Mar 26, 2025

Failing tests are related to timestamp not matching in Logger middleware. For some reason GitHub doesn't let me replay them

@ReneWerner87 ReneWerner87 merged commit dab20c9 into main Mar 26, 2025
25 of 28 checks passed
@github-project-automation github-project-automation bot moved this to Done in v3 Mar 26, 2025
efectn pushed a commit to ckoch786/fiber that referenced this pull request May 15, 2025
Add benchmarks for default case with Immutable
@gaby gaby deleted the immutable-benchmark branch June 18, 2025 02:08
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.

2 participants