-
Notifications
You must be signed in to change notification settings - Fork 338
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
[nfc] api headers benchmark #1089
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2023 Cloudflare, Inc. | ||
// Licensed under the Apache 2.0 license found in the LICENSE file or at: | ||
// https://opensource.org/licenses/Apache-2.0 | ||
|
||
#include <workerd/tests/bench-tools.h> | ||
#include <workerd/tests/test-fixture.h> | ||
#include <workerd/api/http.h> | ||
|
||
// A benchmark for js Header class. | ||
|
||
namespace workerd { | ||
namespace { | ||
|
||
struct ApiHeaders: public benchmark::Fixture { | ||
virtual ~ApiHeaders() noexcept(true) {} | ||
|
||
|
||
void SetUp(benchmark::State& state) noexcept(true) override { | ||
fixture = kj::heap<TestFixture>(); | ||
|
||
kj::HttpHeaderTable::Builder builder; | ||
builder.add("Host"); | ||
builder.add("Accept"); | ||
builder.add("Content-Type"); | ||
builder.add("Last-Modified"); | ||
table = builder.build(); | ||
kjHeaders = kj::heap<kj::HttpHeaders>(*table); | ||
auto in = kj::heapString( | ||
"GET /favicon.ico HTTP/1.1\r\n" | ||
"Host: 0.0.0.0=5000\r\n" | ||
"User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008061015 Firefox/3.0\r\n" | ||
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" | ||
"Accept-Language: en-us,en;q=0.5\r\n" | ||
"Accept-Encoding: gzip,deflate\r\n" | ||
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" | ||
"Keep-Alive: 300\r\n" | ||
"Connection: keep-alive\r\n" | ||
"\r\n"); | ||
KJ_EXPECT(kjHeaders->tryParseRequest(in.asArray()).is<kj::HttpHeaders::Request>()); | ||
} | ||
|
||
void TearDown(benchmark::State& state) noexcept(true) override { | ||
fixture = nullptr; | ||
} | ||
|
||
kj::Own<TestFixture> fixture; | ||
kj::Own<kj::HttpHeaderTable> table; | ||
kj::Own<kj::HttpHeaders> kjHeaders; | ||
}; | ||
|
||
// initialization performs a lot of copying, benchmark it | ||
BENCHMARK_F(ApiHeaders, constructor)(benchmark::State& state) { | ||
fixture->runInIoContext([&](const TestFixture::Environment& env) { | ||
for (auto _ : state) { | ||
auto jsHeaders = jsg::alloc<api::Headers>(*kjHeaders, api::Headers::Guard::REQUEST); | ||
} | ||
}); | ||
} | ||
|
||
} // namespace | ||
} // namespace workerd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR LGTM overall, but can you explain what the virtual destructor and
fixture = nullptr;
statements are used for? I'd imagine that the virtual destructor means that just the benchmark::Fixture destructor is used and that fixture is set to nullptr so that kj::Own knows it can free it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
virtual destructor is needed to annotate it by noexcept. otherwise in our code base clang assumes it has a different exception specification.
I use
fixture = null
to force- destroy an Isolate. Not entirely sure what's the fixture lifecycle yet.