From cda599733da038366d2dce55172967eef789df80 Mon Sep 17 00:00:00 2001 From: Daniel Eggert Date: Tue, 17 Nov 2026 20:07:10 +0100 Subject: [PATCH] Make IMAPBuffer.dispatchDonationThreshold internal A tuning value nothing outside Core needs. Docs outside it now give the number instead of the name. --- .../IMAPDispatchClient/DispatchClient+Current.swift | 4 ++-- Sources/NIOIMAP/Bytes/ByteBufferOutput.swift | 4 ++-- Sources/NIOIMAPCore/Bytes/ByteRegion.swift | 2 +- Sources/NIOIMAPCore/Bytes/IMAPBufferList+DispatchData.swift | 6 +++--- Tests/NIOIMAPTests/Bytes/IMAPBufferByteBufferTests.swift | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Examples/PerformanceTester/Benchmarks/IMAPDispatchClient/DispatchClient+Current.swift b/Examples/PerformanceTester/Benchmarks/IMAPDispatchClient/DispatchClient+Current.swift index f0d728c8..4306e412 100644 --- a/Examples/PerformanceTester/Benchmarks/IMAPDispatchClient/DispatchClient+Current.swift +++ b/Examples/PerformanceTester/Benchmarks/IMAPDispatchClient/DispatchClient+Current.swift @@ -23,8 +23,8 @@ import NIOIMAPCore // The "after" half: the client this library is designed for. Received regions are appended to an // `IMAPInputBuffer` and parsed where they landed; encoded bytes are written into segments the encoder -// owns and then donated to a `DispatchData`, or copied into it when shorter than -// `IMAPBuffer.dispatchDonationThreshold`. Nothing on either path copies a payload. +// owns and then donated to a `DispatchData`, or copied into it when shorter than the dispatch +// donation threshold (512 B). Nothing on either path copies a payload. // // Every function here has a same-signature twin in `DispatchClient+Legacy.swift`. Keep them in step: // the comparison is only meaningful if the two configurations do the same work in the same order, and diff --git a/Sources/NIOIMAP/Bytes/ByteBufferOutput.swift b/Sources/NIOIMAP/Bytes/ByteBufferOutput.swift index 86c12710..6d5f15b1 100644 --- a/Sources/NIOIMAP/Bytes/ByteBufferOutput.swift +++ b/Sources/NIOIMAP/Bytes/ByteBufferOutput.swift @@ -34,8 +34,8 @@ import NIOIMAPCore /// it. Per-write cost does not decide it: the encoder stages small writes, so either sink sees about /// one append per 256 bytes. The hand-out does. This sink is zero-copy into `ByteBuffer`s — its /// regions are slices — where ``IMAPOutputBuffer`` copies its regions into fresh `ByteBuffer`s. Into a -/// `DispatchData` they are alike: each donates regions of at least -/// `IMAPBuffer.dispatchDonationThreshold` bytes and copies shorter ones. Both keep large payloads by +/// `DispatchData` they are alike: each donates regions of at least the dispatch donation threshold +/// (512 B) and copies shorter ones. Both keep large payloads by /// reference, so neither wins there. Measured on a stream of small responses into a `Channel`, this /// sink allocates fewer bytes but is slower, and while earlier responses are still in flight it is /// slower still and allocates more bytes (see below). So it ships as a caller's choice. diff --git a/Sources/NIOIMAPCore/Bytes/ByteRegion.swift b/Sources/NIOIMAPCore/Bytes/ByteRegion.swift index 64ec00d9..afcde6a9 100644 --- a/Sources/NIOIMAPCore/Bytes/ByteRegion.swift +++ b/Sources/NIOIMAPCore/Bytes/ByteRegion.swift @@ -58,7 +58,7 @@ extension ContiguousArray: ByteRegion where Element == UInt8 {} /// address, and those bytes stay valid and unchanged for as long as any copy of the value is alive. /// In return, the library keeps a copy of the value where it would otherwise copy the bytes: /// ``IMAPInputBuffer`` keeps a large region by reference, and ``IMAPBufferList/makeDispatchData()`` -/// donates a region of at least ``IMAPBuffer/dispatchDonationThreshold`` bytes to the `DispatchData`. +/// donates a region of at least the dispatch donation threshold (512 B) to the `DispatchData`. /// /// This is the extension point for a byte-buffer type of your own; `NIOIMAP` conforms `ByteBuffer` /// with nothing more. A region that does not conform is copied instead, which is always correct. diff --git a/Sources/NIOIMAPCore/Bytes/IMAPBufferList+DispatchData.swift b/Sources/NIOIMAPCore/Bytes/IMAPBufferList+DispatchData.swift index b34d722d..7f5496b9 100644 --- a/Sources/NIOIMAPCore/Bytes/IMAPBufferList+DispatchData.swift +++ b/Sources/NIOIMAPCore/Bytes/IMAPBufferList+DispatchData.swift @@ -59,14 +59,14 @@ extension IMAPBuffer { /// /// At most ``copyThreshold``, so a region the encoder kept by reference is never copied for being /// short. It is a tuning value and may change between releases. - public static let dispatchDonationThreshold = 512 + internal static let dispatchDonationThreshold = 512 } extension IMAPBufferList { /// Converts to a `DispatchData`, without copying where it pays. /// - /// A region of at least ``IMAPBuffer/dispatchDonationThreshold`` bytes is donated rather than - /// copied when its address is fixed: bytes this library owns, or a region whose owner is a + /// A region of at least 512 bytes (a tuning value that may change) is donated rather than copied + /// when its address is fixed: bytes this library owns, or a region whose owner is a /// ``StableAddressByteRegion``. The `DispatchData` adopts the memory and keeps its owner alive. /// Each run of the other regions — shorter, or without a fixed address — is copied into one /// allocation, which becomes one `DispatchData` region. diff --git a/Tests/NIOIMAPTests/Bytes/IMAPBufferByteBufferTests.swift b/Tests/NIOIMAPTests/Bytes/IMAPBufferByteBufferTests.swift index f488f634..e6eacc09 100644 --- a/Tests/NIOIMAPTests/Bytes/IMAPBufferByteBufferTests.swift +++ b/Tests/NIOIMAPTests/Bytes/IMAPBufferByteBufferTests.swift @@ -15,7 +15,7 @@ import Dispatch import NIO import NIOIMAP -import NIOIMAPCore +@testable import NIOIMAPCore import Testing /// The address of a `ByteBuffer`'s first readable byte — the only way to observe from the outside