-
Notifications
You must be signed in to change notification settings - Fork 11
Index the QPACK static table by name #10
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a2273e8
Index the QPACK static table by name
glbrntt 82e6d4e
Add benchmarks
glbrntt ab178c7
Update Sources/QPACK/Headers/StaticHeaderTable.swift
glbrntt 06ecf9b
Merge branch 'main' into static-table-find
glbrntt ac1fe70
Merge branch 'main' into static-table-find
glbrntt 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 hidden or 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,44 @@ | ||
| // swift-tools-version:6.3 | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the SwiftNIO open source project | ||
| // | ||
| // Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "swift-nio-http3-benchmarks", | ||
| platforms: [ | ||
| .macOS(.v13) | ||
| ], | ||
| dependencies: [ | ||
| .package(path: "../"), | ||
| .package(url: "https://github.com/apple/swift-http-types.git", from: "1.3.0"), | ||
| .package(url: "https://github.com/apple/swift-nio-quic-helpers.git", branch: "main"), | ||
| .package(url: "https://github.com/ordo-one/benchmark.git", from: "1.35.0"), | ||
| ], | ||
| targets: [ | ||
| .executableTarget( | ||
| name: "QPACKBenchmarks", | ||
| dependencies: [ | ||
| .product(name: "NIOHTTP3", package: "swift-nio-http3"), | ||
| .product(name: "HTTPTypes", package: "swift-http-types"), | ||
| .product(name: "NIOQUICHelpers", package: "swift-nio-quic-helpers"), | ||
| .product(name: "Benchmark", package: "benchmark"), | ||
| ], | ||
| path: "QPACKBenchmarks", | ||
| plugins: [ | ||
| .plugin(name: "BenchmarkPlugin", package: "benchmark") | ||
| ] | ||
| ) | ||
| ] | ||
| ) |
This file contains hidden or 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,73 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the SwiftNIO open source project | ||
| // | ||
| // Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import Benchmark | ||
| import HTTPTypes | ||
| @_spi(Benchmarks) import NIOHTTP3 | ||
| import NIOQUICHelpers | ||
|
|
||
| /// A realistic request header set for a browser GET, exercising a mix of exact | ||
| /// static-table matches (`:method GET`), name-only matches (`:authority`) and | ||
| /// headers absent from the table (`x-custom-header`). | ||
| private let requestHeaders: [HTTPField] = [ | ||
| HTTPField(name: .init(parsed: ":method")!, value: "GET"), | ||
| HTTPField(name: .init(parsed: ":scheme")!, value: "https"), | ||
| HTTPField(name: .init(parsed: ":authority")!, value: "www.example.com"), | ||
| HTTPField(name: .init(parsed: ":path")!, value: "/index.html"), | ||
| HTTPField(name: .init(parsed: "user-agent")!, value: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)"), | ||
| HTTPField(name: .init(parsed: "accept")!, value: "*/*"), | ||
| HTTPField(name: .init(parsed: "accept-encoding")!, value: "gzip, deflate, br"), | ||
| HTTPField(name: .init(parsed: "accept-language")!, value: "en-US,en;q=0.9"), | ||
| HTTPField(name: .init(parsed: "cache-control")!, value: "no-cache"), | ||
| HTTPField(name: .init(parsed: "cookie")!, value: "session=abc123def456; theme=dark"), | ||
| HTTPField(name: .init(parsed: "referer")!, value: "https://www.example.com/"), | ||
| HTTPField(name: .init(parsed: "x-custom-header")!, value: "some-custom-value"), | ||
| ] | ||
|
|
||
| let benchmarks: @Sendable () -> Void = { | ||
| // Exercises StaticHeaderTable.find on every header, with no dynamic table. | ||
| Benchmark( | ||
| "QPACKStaticEncode_BrowserGET", | ||
| configuration: .init( | ||
| metrics: [.mallocCountTotal, .instructions, .wallClock], | ||
| scalingFactor: .kilo | ||
| ) | ||
| ) { benchmark in | ||
| for _ in benchmark.scaledIterations { | ||
| blackHole(QPACKBenchmarks.staticEncode(headers: requestHeaders)) | ||
| } | ||
| } | ||
|
|
||
| // Exercises the static-table lookup plus the dynamic table on every header. | ||
| Benchmark( | ||
| "QPACKDynamicEncode_BrowserGET", | ||
| configuration: .init( | ||
| metrics: [.mallocCountTotal, .instructions, .wallClock], | ||
| scalingFactor: .kilo | ||
| ) | ||
| ) { benchmark in | ||
| for _ in benchmark.scaledIterations { | ||
| blackHole( | ||
| QPACKBenchmarks.dynamicEncode( | ||
| headers: requestHeaders, | ||
| streamID: QUICStreamID(rawValue: 0), | ||
| dynamicTableMaxCapacity: 4096, | ||
| dynamicTableInitialCapacity: 4096, | ||
| maxBlockedStreams: 100, | ||
| targetEvictableFraction: 0.5 | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,55 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the SwiftNIO open source project | ||
| // | ||
| // Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| public import HTTPTypes | ||
| public import NIOQUICHelpers | ||
| private import QPACK | ||
|
|
||
| // QPACK isn't a library product, so add entry points for benchmarks here under SPI. | ||
| @_spi(Benchmarks) | ||
| public enum QPACKBenchmarks { | ||
| /// Encode `headers` with the static-only encoder. Returns the number of field lines | ||
| /// produced. | ||
| /// | ||
| /// The return value doesn't matter, but needs to be there so the calling benchmark | ||
| /// can stop the function call from being optimised away. | ||
| @_spi(Benchmarks) | ||
| public static func staticEncode(headers: [HTTPField]) -> Int { | ||
| let encoder = StaticQPACKEncoder() | ||
| return encoder.encode(headers: headers).lines.count | ||
| } | ||
|
|
||
| /// Create a dynamic encoder and encode `headers` on `streamID`. Returns the number | ||
| /// of field lines produced. | ||
| /// | ||
| /// The return value doesn't matter, but needs to be there so the calling benchmark | ||
| /// can stop the function call from being optimised away. | ||
| @_spi(Benchmarks) | ||
| public static func dynamicEncode( | ||
| headers: [HTTPField], | ||
| streamID: QUICStreamID, | ||
| dynamicTableMaxCapacity: Int, | ||
| dynamicTableInitialCapacity: Int, | ||
| maxBlockedStreams: Int, | ||
| targetEvictableFraction: Double | ||
| ) -> Int { | ||
| var (encoder, _) = DynamicQPACKEncoder.create( | ||
| dynamicTableMaxCapacity: dynamicTableMaxCapacity, | ||
| dynamicTableInitialCapacity: dynamicTableInitialCapacity, | ||
| maxBlockedStreams: maxBlockedStreams, | ||
| targetEvictableFraction: targetEvictableFraction | ||
| ) | ||
| return encoder.encode(headers: headers, forStream: streamID).fieldSection.lines.count | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.