@@ -124,7 +124,7 @@ public void Dispose()
124124/// </summary>
125125/// <remarks>
126126/// This cache uses a fixed lookup table with 2,097,152 bins, each storing a 2-byte value,
127- /// resulting in a worst-case memory usage of approximately 4 MB. Lookups and insertions are
127+ /// resulting in a memory usage of approximately 4 MB. Lookups and insertions are
128128/// performed in constant time (O(1)) via direct table indexing. This design is optimized for
129129/// speed while maintaining a predictable, fixed memory footprint.
130130/// </remarks>
@@ -209,16 +209,16 @@ public void Dispose()
209209/// </para>
210210/// <para>
211211/// Performance Characteristics:
212- /// - Lookup: O(1) for computing the bucket index from the RGB channels, plus a small constant time (up to 4 iterations)
212+ /// - Lookup: O(1) for computing the bucket index from the RGB channels, plus a small constant time (up to 8 iterations)
213213/// to search through the alpha entries in the bucket.
214214/// - Insertion: O(1) for bucket index computation and a quick linear search over a very small (fixed) number of entries.
215215/// </para>
216216/// <para>
217217/// Memory Characteristics:
218218/// - The cache consists of 32,768 buckets.
219- /// - Each <see cref="AlphaBucket"/> is implemented using an inline array with a capacity of 4 entries.
220- /// - Each bucket occupies approximately 18 bytes.
221- /// - Overall, the buckets occupy roughly 32,768 × 18 = 589,824 bytes (576 KB).
219+ /// - Each <see cref="AlphaBucket"/> is implemented using an inline array with a capacity of 8 entries.
220+ /// - Each bucket occupies approximately 1 byte (Count) + (8 entries × 3 bytes each) ≈ 25 bytes.
221+ /// - Overall, the buckets occupy roughly 32,768 × 25 bytes = 819,200 bytes (≈ 800 KB).
222222/// </para>
223223/// <para>
224224/// This design provides nearly constant-time lookup and insertion with minimal memory usage,
@@ -304,27 +304,27 @@ public struct AlphaEntry
304304 public struct AlphaBucket
305305 {
306306 // Fixed capacity for alpha entries in this bucket.
307- // We choose a capacity of 4 for several reasons:
307+ // We choose a capacity of 8 for several reasons:
308308 //
309309 // 1. The alpha channel is quantized to 6 bits, so there are 64 possible distinct values.
310310 // In the worst-case, a given RGB bucket might encounter up to 64 different alpha values.
311311 //
312312 // 2. However, in practice (based on probability theory and typical image data),
313313 // the number of unique alpha values that actually occur for a given quantized RGB
314- // bucket is usually very small. If you randomly sample 4 values out of 64,
314+ // bucket is usually very small. If you randomly sample 8 values out of 64,
315315 // the probability that these 4 samples are all unique is high if the distribution
316316 // of alpha values is skewed or if only a few alpha values are used.
317317 //
318318 // 3. Statistically, for many real-world images, most RGB buckets will have only a couple
319- // of unique alpha values. Allocating 4 slots per bucket provides a good trade-off:
319+ // of unique alpha values. Allocating 8 slots per bucket provides a good trade-off:
320320 // it captures the common-case scenario while keeping overall memory usage low.
321321 //
322- // 4. Even if more than 4 unique alpha values occur in a bucket,
322+ // 4. Even if more than 8 unique alpha values occur in a bucket,
323323 // our design overwrites the first entry. This behavior gives us some "wriggle room"
324324 // while preserving the most frequently encountered or most recent values.
325- public const int Capacity = 4 ;
325+ public const int Capacity = 8 ;
326326 public byte Count ;
327- private InlineArray4 < AlphaEntry > entries ;
327+ private InlineArray8 < AlphaEntry > entries ;
328328
329329 [ MethodImpl ( InliningOptions . ShortMethod ) ]
330330 public bool TryGetValue ( byte quantizedAlpha , out short paletteIndex )
0 commit comments