Make IMAPBuffer.dispatchDonationThreshold internal

A tuning value nothing outside Core needs. Docs outside it now give
the number instead of the name.
This commit is contained in:
Daniel Eggert committed 2026-11-25 21:19:42 +09:00
1 parent e990d48689
commit cda599733d
5 files changed
+9 -9

No files matched your search

@@ -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
+2 -2
View File
@@ -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.
+1 -1
View File
@@ -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.
@@ -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.
@@ -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