-
Notifications
You must be signed in to change notification settings - Fork 734
feat: Upstream NIOAsyncRuntime from PassiveLogic to swift-nio #3487
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
Open
scottmarchant
wants to merge
1
commit into
apple:main
Choose a base branch
from
PassiveLogic:feat/upstreamNIOAsyncRuntime
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,756
−0
Open
Changes from all commits
Commits
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
127 changes: 127 additions & 0 deletions
127
Benchmarks/Benchmarks/NIOAsyncRuntimeBenchmarks/Benchmarks.swift
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,127 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // NOTE: By and large the benchmarks here were ported from swift-nio | ||
| // to allow side-by-side performance comparison | ||
| // | ||
| // See https://github.com/apple/swift-nio/blob/main/Benchmarks/Benchmarks/NIOPosixBenchmarks/Benchmarks.swift | ||
|
|
||
| import Benchmark | ||
| import NIOAsyncRuntime | ||
| import NIOCore | ||
|
|
||
| let benchmarks = { | ||
| if #available(macOS 15, iOS 18, tvOS 18, watchOS 11, *) { | ||
| let eventLoop = AsyncEventLoopGroup.singleton.next() | ||
|
|
||
| let defaultMetrics: [BenchmarkMetric] = [ | ||
| .mallocCountTotal, | ||
| .contextSwitches, | ||
| .wallClock, | ||
| ] | ||
|
|
||
| Benchmark( | ||
| "MTELG.immediateTasksThroughput", | ||
| configuration: Benchmark.Configuration( | ||
| metrics: defaultMetrics, | ||
| scalingFactor: .mega, | ||
| maxDuration: .seconds(10_000_000), | ||
| maxIterations: 5 | ||
| ) | ||
| ) { benchmark in | ||
| func noOp() {} | ||
| for _ in benchmark.scaledIterations { | ||
| eventLoop.execute { noOp() } | ||
| } | ||
| } | ||
|
|
||
| Benchmark( | ||
| "MTELG.scheduleTask(in:_:)", | ||
| configuration: Benchmark.Configuration( | ||
| metrics: defaultMetrics, | ||
| scalingFactor: .kilo, | ||
| maxDuration: .seconds(10_000_000), | ||
| maxIterations: 5 | ||
| ) | ||
| ) { benchmark in | ||
| for _ in benchmark.scaledIterations { | ||
| eventLoop.scheduleTask(in: .hours(1), {}) | ||
| } | ||
| } | ||
|
|
||
| Benchmark( | ||
| "MTELG.scheduleCallback(in:_:)", | ||
| configuration: Benchmark.Configuration( | ||
| metrics: defaultMetrics, | ||
| scalingFactor: .mega, | ||
| maxDuration: .seconds(10_000_000), | ||
| maxIterations: 5, | ||
| // NOTE: Jan 29 2026. This test crashes in CI, but not locally, making a fix difficult. | ||
| // Skipping the benchmark for now. | ||
| skip: true | ||
| ) | ||
| ) { benchmark in | ||
| final class Timer: NIOScheduledCallbackHandler { | ||
| func handleScheduledCallback(eventLoop: some EventLoop) {} | ||
| } | ||
| let timer = Timer() | ||
|
|
||
| benchmark.startMeasurement() | ||
| for _ in benchmark.scaledIterations { | ||
| let handle = try! eventLoop.scheduleCallback(in: .hours(1), handler: timer) | ||
| } | ||
| } | ||
|
|
||
| Benchmark( | ||
| "Jump to EL and back using execute and unsafecontinuation", | ||
| configuration: .init( | ||
| metrics: defaultMetrics, | ||
| scalingFactor: .kilo | ||
| ) | ||
| ) { benchmark in | ||
| for _ in benchmark.scaledIterations { | ||
| await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) in | ||
| eventLoop.execute { | ||
| continuation.resume() | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| final actor Foo { | ||
| nonisolated public let unownedExecutor: UnownedSerialExecutor | ||
|
|
||
| init(eventLoop: any EventLoop) { | ||
| self.unownedExecutor = eventLoop.executor.asUnownedSerialExecutor() | ||
| } | ||
|
|
||
| func foo() { | ||
| blackHole(Void()) | ||
| } | ||
| } | ||
|
|
||
| Benchmark( | ||
| "Jump to EL and back using actor with EL executor", | ||
| configuration: .init( | ||
| metrics: defaultMetrics, | ||
| scalingFactor: .kilo | ||
| ) | ||
| ) { benchmark in | ||
| let actor = Foo(eventLoop: eventLoop) | ||
| for _ in benchmark.scaledIterations { | ||
| await actor.foo() | ||
| } | ||
| } | ||
| } | ||
| } |
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
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.