Skip to content
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

perf: avoid stringify when set header #1220

Merged
merged 4 commits into from
Jul 12, 2018
Merged

perf: avoid stringify when set header #1220

merged 4 commits into from
Jul 12, 2018

Conversation

dead-horse
Copy link
Member

No description provided.

@dead-horse dead-horse requested a review from fengmk2 July 11, 2018 12:03
lib/response.js Outdated
if (Array.isArray(val)) val = val.map(String);
else val = String(val);
// maybe we can drop support of undefined in the next major version
if (val === undefined) val = 'undefined';
Copy link
Member Author

Choose a reason for hiding this comment

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

other type of values will be stringify in res.setHeader

Copy link
Member

Choose a reason for hiding this comment

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

res.getHeader will broken change after this change.

Copy link
Member

Choose a reason for hiding this comment

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

Sets a single header value for headers object. If this header already exists in the to-be-sent headers, its value will be replaced. Use an array of strings here to send multiple headers with the same name. Non-string values will be stored without modification. Therefore, request.getHeader() may return non-string values. However, the non-string values will be converted to strings for network transmission.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@dead-horse
Copy link
Member Author

about ~3% performance improve.

-before
image

  • after

image

@codecov
Copy link

codecov bot commented Jul 11, 2018

Codecov Report

Merging #1220 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1220   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files           5       5           
  Lines         391     391           
======================================
  Hits          391     391
Impacted Files Coverage Δ
lib/response.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c6b8782...4499e99. Read the comment docs.

@dead-horse dead-horse merged commit 0b93066 into master Jul 12, 2018
@fengmk2 fengmk2 deleted the avoid-stringify branch July 24, 2018 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants