Skip to content

perf: optimization of request instantiation#3107

Merged
mcollina merged 17 commits into
nodejs:mainfrom
tsctx:perf/optimization-of-request-creation
Jun 6, 2024
Merged

perf: optimization of request instantiation#3107
mcollina merged 17 commits into
nodejs:mainfrom
tsctx:perf/optimization-of-request-creation

Conversation

@tsctx

@tsctx tsctx commented Apr 13, 2024

Copy link
Copy Markdown
Member
  1. Reuse fetch optimization logic in core.
  2. Avoid lowercasing.

@codecov-commenter

codecov-commenter commented Apr 13, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 98.21429% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 94.16%. Comparing base (ad9b5bd) to head (4cf7be2).

Files Patch % Lines
lib/web/fetch/util.js 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3107      +/-   ##
==========================================
- Coverage   94.17%   94.16%   -0.02%     
==========================================
  Files          90       90              
  Lines       24320    24320              
==========================================
- Hits        22904    22901       -3     
- Misses       1416     1419       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Uzlopak Uzlopak changed the title perf: optimization of request creation perf: optimization of request instantiation Apr 13, 2024

@mcollina mcollina 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.

lgtm

@mcollina
mcollina requested a review from KhafraDev April 13, 2024 09:49
Comment thread lib/core/request.js Outdated
Comment thread lib/core/util.js Outdated

@KhafraDev KhafraDev 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.

Is there a reason to combine method validation and normalization into a single method? This instantly breaks the second we need one and not the other.

@tsctx

tsctx commented Apr 13, 2024

Copy link
Copy Markdown
Member Author

Is there a reason to combine method validation and normalization into a single method?

The reason for wanting to normalize and verify at the same time is that the case used in the verification can be reused.

This instantly breaks the second we need one and not the other.

Yes, it is. The function was not changed, but a new one was created.

@metcoder95 metcoder95 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.

Can you share the bench results?

@tsctx

tsctx commented Apr 14, 2024

Copy link
Copy Markdown
Member Author

Can you share the bench results?

Details
import Request from "../../lib/core/request.js";
import DecoratorHandler from "../../lib/handler/decorator-handler.js";

import { bench, group, run } from 'mitata'

const handler = new DecoratorHandler({})

bench('new Request()', () => {
    return new Request('https://localhost', { path: "/", method: "get", body: null }, handler);
})

await run()
  • main
benchmark          time (avg)             (min … max)       p75       p99      p999
----------------------------------------------------- -----------------------------
new Request()     114 ns/iter   (89.75 ns … 2'124 ns)    124 ns    256 ns  1'619 ns```
  • this patch
benchmark          time (avg)             (min … max)       p75       p99      p999
----------------------------------------------------- -----------------------------
new Request()   90.41 ns/iter   (70.85 ns … 1'729 ns)    106 ns    205 ns    717 ns

@Uzlopak

Uzlopak commented Apr 14, 2024

Copy link
Copy Markdown
Contributor

Thank you for the benchmark. Can you add it to the benchmark folder please?

Comment thread lib/web/fetch/request.js Outdated
Comment thread lib/core/util.js

@mcollina mcollina 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.

lgtm

@KhafraDev KhafraDev 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.

validate and normalize are two different things, please split them as the spec states to do

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.

8 participants