Skip to content

Conversation

@ardatan
Copy link
Owner

@ardatan ardatan commented Jul 28, 2025

Followup #2632
This PR adds uWS to the benchmarks, and fixes the regression that is shown in feTS benchmarks

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 28, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added support for running the server using uWebSockets.js, enabling users to benchmark performance with this server option.
  • Bug Fixes
    • Improved handling of string response bodies for better performance and efficiency.
  • Chores
    • Updated benchmark tests to include the new uWebSockets.js scenario.

Walkthrough

The changes introduce support for the "uws" (uWebSockets.js) scenario in the server benchmarking workflow and implementation. The server logic is updated to conditionally start a uWebSockets.js server or a native Node.js HTTP server based on the scenario. Response handling is optimized to efficiently process string bodies without using streams.

Changes

Cohort / File(s) Change Summary
Benchmark Workflow Update
.github/workflows/benchmarks.yml
Added "uws" to the benchmark job matrix scenarios for the "server" job.
Benchmark Server Implementation
benchmarks/server/server.ts
Refactored server startup logic to support both uWebSockets.js and native HTTP servers, based on the SCENARIO environment variable. Adjusted type annotations and imports accordingly.
uWebSockets.js Response Optimization
packages/server/src/uwebsockets.ts
Modified response logic to handle string bodies directly, bypassing streams for improved efficiency.
Changeset Documentation
.changeset/good-signs-hunt.md
Added a changeset describing the patch for string body handling and performance regression fix.

Sequence Diagram(s)

sequenceDiagram
    participant Env as Environment
    participant Main as server.ts
    participant UWS as uWebSockets.js App
    participant HTTP as Node.js HTTP Server

    Env->>Main: Set SCENARIO env variable
    Main->>Main: Check SCENARIO
    alt SCENARIO == "uws"
        Main->>UWS: Create uWebSockets.js app
        UWS->>UWS: Register serverAdapter for all routes
        UWS->>UWS: Listen on port 4000
    else
        Main->>HTTP: Create native HTTP server
        HTTP->>HTTP: Listen on port 4000
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A bunny hops through code so neat,
Now "uws" joins the server fleet!
String bodies flow without a stream,
Benchmarks run with extra gleam.
From corked replies to speedy send,
This patch brings joy—code on, my friend!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 7a44c69 and 0981fe0.

📒 Files selected for processing (4)
  • .changeset/good-signs-hunt.md (1 hunks)
  • .github/workflows/benchmarks.yml (1 hunks)
  • benchmarks/server/server.ts (2 hunks)
  • packages/server/src/uwebsockets.ts (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-uws-bench

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 28, 2025

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@whatwg-node/node-fetch 0.7.23-alpha-20250728110808-0981fe0c7ca2a9d25448c612ffa87274110a432f npm ↗︎ unpkg ↗︎
@whatwg-node/server 0.10.11-alpha-20250728110808-0981fe0c7ca2a9d25448c612ffa87274110a432f npm ↗︎ unpkg ↗︎

@github-actions
Copy link
Contributor

github-actions bot commented Jul 28, 2025

@benchmarks/node-fetch results (noConsumeBody)

   ✓ active_handles.................: avg=139.997474 min=39       med=140     max=192      p(90)=159     p(95)=165    
     data_received..................: 25 MB  816 kB/s
     data_sent......................: 16 MB  528 kB/s
     http_req_blocked...............: avg=3.65µs     min=641ns    med=1.57µs  max=7.41ms   p(90)=2.1µs   p(95)=2.42µs 
     http_req_connecting............: avg=1.42µs     min=0s       med=0s      max=5.61ms   p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=18.68ms    min=1.14ms   med=18.19ms max=792.03ms p(90)=24.39ms p(95)=26.21ms
       { expected_response:true }...: avg=18.68ms    min=1.14ms   med=18.19ms max=792.03ms p(90)=24.39ms p(95)=26.21ms
     http_req_failed................: 0.00%  ✓ 0           ✗ 159983
     http_req_receiving.............: avg=34.48µs    min=8.48µs   med=24.18µs max=22.74ms  p(90)=38.22µs p(95)=45.99µs
     http_req_sending...............: avg=11.53µs    min=2.98µs   med=7.34µs  max=20.55ms  p(90)=10.19µs p(95)=15.37µs
     http_req_tls_handshaking.......: avg=0s         min=0s       med=0s      max=0s       p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=18.63ms    min=985.18µs med=18.15ms max=791.98ms p(90)=24.34ms p(95)=26.15ms
     http_reqs......................: 159983 5332.269866/s
     iteration_duration.............: avg=37.47ms    min=4.61ms   med=36.21ms max=810.18ms p(90)=41.67ms p(95)=46.9ms 
     iterations.....................: 79965  2665.251682/s
     vus............................: 100    min=100       max=100 
     vus_max........................: 100    min=100       max=100 

@github-actions
Copy link
Contributor

github-actions bot commented Jul 28, 2025

@benchmarks/server results (native)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 171264     ✗ 0    
     data_received..................: 17 MB   568 kB/s
     data_sent......................: 13 MB   425 kB/s
     http_req_blocked...............: avg=1.67µs   min=932ns    med=1.64µs   max=202.32µs p(90)=2.05µs   p(95)=2.29µs  
     http_req_connecting............: avg=1ns      min=0s       med=0s       max=153.22µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=272.58µs min=201.49µs med=251.9µs  max=14.32ms  p(90)=285.02µs p(95)=301.62µs
       { expected_response:true }...: avg=272.58µs min=201.49µs med=251.9µs  max=14.32ms  p(90)=285.02µs p(95)=301.62µs
     http_req_failed................: 0.00%   ✓ 0          ✗ 85632
     http_req_receiving.............: avg=27.06µs  min=14.55µs  med=25.83µs  max=3.32ms   p(90)=32.22µs  p(95)=35.1µs  
     http_req_sending...............: avg=9.72µs   min=5.61µs   med=9.74µs   max=236.12µs p(90)=12µs     p(95)=13.85µs 
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=235.8µs  min=173.42µs med=215.77µs max=14.24ms  p(90)=247µs    p(95)=262.73µs
     http_reqs......................: 85632   2854.29553/s
     iteration_duration.............: avg=345.55µs min=264.47µs med=323.74µs max=14.48ms  p(90)=359.57µs p(95)=380.19µs
     iterations.....................: 85632   2854.29553/s
     vus............................: 1       min=1        max=1  
     vus_max........................: 1       min=1        max=1  

@github-actions
Copy link
Contributor

github-actions bot commented Jul 28, 2025

@benchmarks/server results (ponyfill)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 243448      ✗ 0     
     data_received..................: 24 MB   799 kB/s
     data_sent......................: 18 MB   605 kB/s
     http_req_blocked...............: avg=1.54µs   min=902ns    med=1.47µs   max=181.16µs p(90)=1.95µs   p(95)=2.14µs  
     http_req_connecting............: avg=1ns      min=0s       med=0s       max=126.34µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=170.74µs min=115.47µs med=164.42µs max=5.97ms   p(90)=185.28µs p(95)=192.94µs
       { expected_response:true }...: avg=170.74µs min=115.47µs med=164.42µs max=5.97ms   p(90)=185.28µs p(95)=192.94µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 121724
     http_req_receiving.............: avg=24.73µs  min=13.51µs  med=23.6µs   max=3.17ms   p(90)=28.57µs  p(95)=31.61µs 
     http_req_sending...............: avg=9.12µs   min=5.62µs   med=9.21µs   max=290.5µs  p(90)=11.55µs  p(95)=13.16µs 
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=136.89µs min=87.88µs  med=131.03µs max=5.71ms   p(90)=150.01µs p(95)=157.12µs
     http_reqs......................: 121724  4057.340997/s
     iteration_duration.............: avg=241.81µs min=176.28µs med=234.69µs max=6.67ms   p(90)=258.52µs p(95)=268.39µs
     iterations.....................: 121724  4057.340997/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

@github-actions
Copy link
Contributor

github-actions bot commented Jul 28, 2025

@benchmarks/node-fetch results (consumeBody)

   ✓ active_handles.................: avg=139.811818 min=13       med=140     max=185      p(90)=161     p(95)=166    
     data_received..................: 23 MB  761 kB/s
     data_sent......................: 15 MB  488 kB/s
     http_req_blocked...............: avg=3.12µs     min=621ns    med=1.49µs  max=8.54ms   p(90)=2.03µs  p(95)=2.35µs 
     http_req_connecting............: avg=1.14µs     min=0s       med=0s      max=5.52ms   p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=20.01ms    min=160.35µs med=19.57ms max=890.66ms p(90)=25.79ms p(95)=27.08ms
       { expected_response:true }...: avg=20.01ms    min=160.35µs med=19.57ms max=890.66ms p(90)=25.79ms p(95)=27.08ms
     http_req_failed................: 0.00%  ✓ 0           ✗ 149326
     http_req_receiving.............: avg=34.72µs    min=9.12µs   med=24.57µs max=14.36ms  p(90)=38.82µs p(95)=46.26µs
     http_req_sending...............: avg=12.39µs    min=3.28µs   med=7.21µs  max=17.75ms  p(90)=10.08µs p(95)=15.16µs
     http_req_tls_handshaking.......: avg=0s         min=0s       med=0s      max=0s       p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=19.96ms    min=132.37µs med=19.53ms max=890.58ms p(90)=25.74ms p(95)=27.03ms
     http_reqs......................: 149326 4976.376231/s
     iteration_duration.............: avg=40.14ms    min=7.4ms    med=38.81ms max=910.22ms p(90)=43.62ms p(95)=49.37ms
     iterations.....................: 74646  2487.621581/s
     vus............................: 57     min=57        max=100 
     vus_max........................: 100    min=100       max=100 

@github-actions
Copy link
Contributor

github-actions bot commented Jul 28, 2025

@benchmarks/server results (undici)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 168772      ✗ 0    
     data_received..................: 17 MB   560 kB/s
     data_sent......................: 13 MB   419 kB/s
     http_req_blocked...............: avg=1.64µs   min=912ns    med=1.6µs    max=1.07ms   p(90)=1.99µs   p(95)=2.17µs  
     http_req_connecting............: avg=11ns     min=0s       med=0s       max=998.34µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=277.8µs  min=202.3µs  med=255.1µs  max=13.6ms   p(90)=303.71µs p(95)=321.68µs
       { expected_response:true }...: avg=277.8µs  min=202.3µs  med=255.1µs  max=13.6ms   p(90)=303.71µs p(95)=321.68µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 84386
     http_req_receiving.............: avg=28.9µs   min=14.63µs  med=25.52µs  max=2.72ms   p(90)=34.07µs  p(95)=46.11µs 
     http_req_sending...............: avg=9.6µs    min=5.63µs   med=9.56µs   max=2.58ms   p(90)=11.33µs  p(95)=13.2µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=239.3µs  min=175.87µs med=217.9µs  max=13.53ms  p(90)=260.27µs p(95)=280.21µs
     http_reqs......................: 84386   2812.614427/s
     iteration_duration.............: avg=350.78µs min=264µs    med=326.88µs max=13.74ms  p(90)=379.13µs p(95)=399.25µs
     iterations.....................: 84386   2812.614427/s
     vus............................: 0       min=0         max=1  
     vus_max........................: 1       min=1         max=1  

@github-actions
Copy link
Contributor

github-actions bot commented Jul 28, 2025

@benchmarks/server results (uws)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 250666      ✗ 0     
     data_received..................: 21 MB   698 kB/s
     data_sent......................: 19 MB   623 kB/s
     http_req_blocked...............: avg=1.53µs   min=901ns    med=1.47µs   max=1.23ms   p(90)=1.95µs   p(95)=2.09µs  
     http_req_connecting............: avg=0ns      min=0s       med=0s       max=124.11µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=165.33µs min=112.04µs med=156.86µs max=11.85ms  p(90)=177.52µs p(95)=184.69µs
       { expected_response:true }...: avg=165.33µs min=112.04µs med=156.86µs max=11.85ms  p(90)=177.52µs p(95)=184.69µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 125333
     http_req_receiving.............: avg=23.19µs  min=11.74µs  med=21.99µs  max=2.72ms   p(90)=27.14µs  p(95)=29.81µs 
     http_req_sending...............: avg=8.94µs   min=5.55µs   med=9.12µs   max=329.44µs p(90)=10.98µs  p(95)=12.73µs 
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=133.19µs min=84.74µs  med=125.34µs max=11.79ms  p(90)=143.83µs p(95)=150.44µs
     http_reqs......................: 125333  4177.639203/s
     iteration_duration.............: avg=234.86µs min=171.43µs med=225.19µs max=11.97ms  p(90)=249.78µs p(95)=259.27µs
     iterations.....................: 125333  4177.639203/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

@ardatan ardatan marked this pull request as ready for review July 28, 2025 11:18
@ardatan ardatan merged commit 22c568e into master Jul 28, 2025
25 of 26 checks passed
@ardatan ardatan deleted the add-uws-bench branch July 28, 2025 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants