Skip to content

Commit 583d89e

Browse files
Update ref images, tweak lite cache to match original (unused)
1 parent a99e6cf commit 583d89e

41 files changed

Lines changed: 98 additions & 86 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/ImageSharp/Common/InlineArray.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ internal struct InlineArray4<T>
1717
private T t;
1818
}
1919

20+
/// <summary>
21+
/// Represents a safe, fixed sized buffer of 8 elements.
22+
/// </summary>
23+
[InlineArray(8)]
24+
internal struct InlineArray8<T>
25+
{
26+
private T t;
27+
}
28+
2029
/// <summary>
2130
/// Represents a safe, fixed sized buffer of 16 elements.
2231
/// </summary>

src/ImageSharp/Common/InlineArray.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp;
1616
<#GenerateInlineArrays();#>
1717

1818
<#+
19-
private static int[] Lengths = new int[] {4, 16 };
19+
private static int[] Lengths = new int[] {4, 8, 16 };
2020

2121
void GenerateInlineArrays()
2222
{

src/ImageSharp/Processing/Processors/Quantization/IColorIndexCache.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
Lines changed: 3 additions & 0 deletions
Lines changed: 2 additions & 2 deletions
Lines changed: 2 additions & 2 deletions
Lines changed: 2 additions & 2 deletions
Lines changed: 2 additions & 2 deletions
Lines changed: 2 additions & 2 deletions
Lines changed: 2 additions & 2 deletions

0 commit comments

Comments
 (0)