diff --git a/IntegrationTests/tests_04_performance/test_01_resources/test_future_erase_result.swift b/IntegrationTests/tests_04_performance/test_01_resources/test_future_erase_result.swift new file mode 100644 index 0000000000..d2d565efd8 --- /dev/null +++ b/IntegrationTests/tests_04_performance/test_01_resources/test_future_erase_result.swift @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftNIO open source project +// +// Copyright (c) 2021 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 NIO + +func run(identifier: String) { + measure(identifier: identifier) { + @inline(never) + func doEraseResult(loop: EventLoop) { + // In an ideal implementation the only allocation is this promise. + let p = loop.makePromise(of: Int.self) + let f = p.futureResult.map { (r: Int) -> Void in + // This closure is a value-to-no-value erase that closes over nothing. + // Ideally this would not allocate. + return + }.map { (_: Void) -> Void in + // This closure is a nothing-to-nothing map, basically a "completed" observer. This should + // also not allocate, but it has a separate code path to the above. + } + p.succeed(0) + } + + let el = EmbeddedEventLoop() + for _ in 0..<1000 { + doEraseResult(loop: el) + } + return 1000 + } +} diff --git a/docker/docker-compose.1604.52.yaml b/docker/docker-compose.1604.52.yaml index 0461ab79d6..79e926112e 100644 --- a/docker/docker-compose.1604.52.yaml +++ b/docker/docker-compose.1604.52.yaml @@ -41,6 +41,7 @@ services: - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_holding_buffer_with_space=3 - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_new_buffer=3050 - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_new_buffer_with_space=3050 + - MAX_ALLOCS_ALLOWED_future_erase_result=4050 - MAX_ALLOCS_ALLOWED_future_lots_of_callbacks=60050 - MAX_ALLOCS_ALLOWED_modifying_1000_circular_buffer_elements=0 - MAX_ALLOCS_ALLOWED_modifying_byte_buffer_view=2050 diff --git a/docker/docker-compose.1604.53.yaml b/docker/docker-compose.1604.53.yaml index d5368b9c34..d48b152344 100644 --- a/docker/docker-compose.1604.53.yaml +++ b/docker/docker-compose.1604.53.yaml @@ -41,6 +41,7 @@ services: - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_holding_buffer_with_space=3 - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_new_buffer=3050 - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_new_buffer_with_space=3050 + - MAX_ALLOCS_ALLOWED_future_erase_result=4050 - MAX_ALLOCS_ALLOWED_future_lots_of_callbacks=60050 - MAX_ALLOCS_ALLOWED_modifying_1000_circular_buffer_elements=0 - MAX_ALLOCS_ALLOWED_modifying_byte_buffer_view=2050 diff --git a/docker/docker-compose.1804.51.yaml b/docker/docker-compose.1804.51.yaml index f3c2110cb6..9cc6504252 100644 --- a/docker/docker-compose.1804.51.yaml +++ b/docker/docker-compose.1804.51.yaml @@ -41,6 +41,7 @@ services: - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_holding_buffer_with_space=3 - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_new_buffer=3050 - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_new_buffer_with_space=3050 + - MAX_ALLOCS_ALLOWED_future_erase_result=4050 - MAX_ALLOCS_ALLOWED_future_lots_of_callbacks=60050 - MAX_ALLOCS_ALLOWED_modifying_1000_circular_buffer_elements=0 - MAX_ALLOCS_ALLOWED_modifying_byte_buffer_view=6050 diff --git a/docker/docker-compose.2004.54.yaml b/docker/docker-compose.2004.54.yaml index c8abb4c4b7..bf31598aaf 100644 --- a/docker/docker-compose.2004.54.yaml +++ b/docker/docker-compose.2004.54.yaml @@ -41,6 +41,7 @@ services: - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_holding_buffer_with_space=3 - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_new_buffer=3050 - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_new_buffer_with_space=3050 + - MAX_ALLOCS_ALLOWED_future_erase_result=4050 - MAX_ALLOCS_ALLOWED_future_lots_of_callbacks=60050 - MAX_ALLOCS_ALLOWED_modifying_1000_circular_buffer_elements=0 - MAX_ALLOCS_ALLOWED_modifying_byte_buffer_view=2050 diff --git a/docker/docker-compose.2004.main.yaml b/docker/docker-compose.2004.main.yaml index 127f83e9f6..ac3fbf7209 100644 --- a/docker/docker-compose.2004.main.yaml +++ b/docker/docker-compose.2004.main.yaml @@ -41,6 +41,7 @@ services: - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_holding_buffer_with_space=3 - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_new_buffer=3050 - MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_new_buffer_with_space=3050 + - MAX_ALLOCS_ALLOWED_future_erase_result=4050 - MAX_ALLOCS_ALLOWED_future_lots_of_callbacks=60050 - MAX_ALLOCS_ALLOWED_modifying_1000_circular_buffer_elements=0 - MAX_ALLOCS_ALLOWED_modifying_byte_buffer_view=2050