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

http2: code style and performance improvements #16239

Closed
wants to merge 12 commits into from

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Oct 16, 2017

A number of code style and performance improvements to the http2 internals.

A significant chunk of this involves removing some of the safety checks that were left in while things were being developed. Because the code has stablized, these are less necessary. Removing these yields a significant performance improvement.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

http2

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Oct 16, 2017
@jasnell jasnell requested a review from mcollina October 16, 2017 19:22
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM. how much do we gain by disabling the checks?

Copy link
Member

@apapirovski apapirovski left a comment

Choose a reason for hiding this comment

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

👍

@@ -6,7 +6,8 @@ const PORT = common.PORT;
const bench = common.createBenchmark(main, {
n: [1e3],
nheaders: [0, 10, 100, 1000],
}, { flags: ['--no-warnings'] });
benchmarker: ['h2load']
}, { flags: ['--no-warnings', '--expose-http2'] });
Copy link
Member

Choose a reason for hiding this comment

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

Any specific reason --expose-http2 is back in? Is it just so compare can be run against versions where that was required?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep. It's for benchmark comparisons against v8.x

@jasnell
Copy link
Member Author

jasnell commented Oct 16, 2017

how much do we gain by disabling the checks?

About an extra ~1k reqs per second.

With the checks and if-branches removed, I'm seeing a boost of about ~7k reqs per second with my limited benchmarking.

@jasnell
Copy link
Member Author

jasnell commented Oct 16, 2017

Almost all of these checks are in hot paths btw

@jasnell
Copy link
Member Author

jasnell commented Oct 17, 2017

@mcollina ... please take another look at this, in particular the last commit. All current tests are passing and performance is improved... we'll need to test this further tho.

@jasnell
Copy link
Member Author

jasnell commented Oct 18, 2017

any reason for using std::list here?

No specific reason, and no specific preference, to be honest :-)

@jasnell
Copy link
Member Author

jasnell commented Oct 18, 2017

@addaleax ... there... now using deque ;-)

CHECK_EQ(data_chunks_head_, nullptr);
CHECK_EQ(data_chunks_tail_, nullptr);
CHECK_EQ(current_headers_head_, nullptr);
CHECK_EQ(current_headers_tail_, nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

These are supposed to check emptyness, right? That can still happen if we like.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, but they're largely worthless checks. The Nghttp2Stream instances are pooled are only rarely actually destroyed so these checks aren't really helping us with much. I had them in there largely to test for correctness as I was writing the code.

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

:shipit:

@jasnell
Copy link
Member Author

jasnell commented Oct 20, 2017

@jasnell
Copy link
Member Author

jasnell commented Oct 20, 2017

The misbehaving flow control tests are failing on Windows so I'll need to get that checked out before this can land.

@jasnell
Copy link
Member Author

jasnell commented Oct 22, 2017

Copy link
Member

@apapirovski apapirovski left a comment

Choose a reason for hiding this comment

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

Changes look good, confirming my approval.

jasnell added a commit that referenced this pull request Oct 23, 2017
PR-URL: #16239
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
jasnell added a commit that referenced this pull request Oct 23, 2017
* move CHECK statements into DEBUG checks
* improve performance by removing branches
  * Several if checks were left in while the code was being developed.
    Now that the core API has stablized more, the checks are largely
    unnecessary and can be removed, yielding a significant boost in
    performance.
* refactor flow control for proper backpressure
* use std::queue for inbound headers
* use std::queue for outbound data
* remove now unnecessary FreeHeaders function
* expand comments and miscellaneous edits
* add a couple of misbehaving flow control tests

PR-URL: #16239
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
@jasnell
Copy link
Member Author

jasnell commented Oct 23, 2017

Landed in 82b1660 and f16b9c1

@jasnell jasnell closed this Oct 23, 2017
MylesBorins pushed a commit that referenced this pull request Oct 23, 2017
PR-URL: #16239
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
MylesBorins pushed a commit that referenced this pull request Oct 23, 2017
* move CHECK statements into DEBUG checks
* improve performance by removing branches
  * Several if checks were left in while the code was being developed.
    Now that the core API has stablized more, the checks are largely
    unnecessary and can be removed, yielding a significant boost in
    performance.
* refactor flow control for proper backpressure
* use std::queue for inbound headers
* use std::queue for outbound data
* remove now unnecessary FreeHeaders function
* expand comments and miscellaneous edits
* add a couple of misbehaving flow control tests

PR-URL: #16239
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Oct 26, 2017
PR-URL: nodejs/node#16239
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Oct 26, 2017
* move CHECK statements into DEBUG checks
* improve performance by removing branches
  * Several if checks were left in while the code was being developed.
    Now that the core API has stablized more, the checks are largely
    unnecessary and can be removed, yielding a significant boost in
    performance.
* refactor flow control for proper backpressure
* use std::queue for inbound headers
* use std::queue for outbound data
* remove now unnecessary FreeHeaders function
* expand comments and miscellaneous edits
* add a couple of misbehaving flow control tests

PR-URL: nodejs/node#16239
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Dec 7, 2017
PR-URL: nodejs/node#16239
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Dec 7, 2017
* move CHECK statements into DEBUG checks
* improve performance by removing branches
  * Several if checks were left in while the code was being developed.
    Now that the core API has stablized more, the checks are largely
    unnecessary and can be removed, yielding a significant boost in
    performance.
* refactor flow control for proper backpressure
* use std::queue for inbound headers
* use std::queue for outbound data
* remove now unnecessary FreeHeaders function
* expand comments and miscellaneous edits
* add a couple of misbehaving flow control tests

PR-URL: nodejs/node#16239
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants