Repository navigation
Performance Sprite Region Read
Readable RGBA32 sprite queries now copy the selected rectangle from the base mip, rather than copying the entire texture. The intermediate pixel array holds only that rectangle. Pixel colours, alpha policy, pivots and units per pixel retain their existing meaning. The managed copy owns its pixels; changing it does not change the texture. Full-texture reads retain their existing conversion path. RGB24 subregions are covered by the later comparison; additional formats are described below.
Three fresh-process pairs on Windows x64 Unity 6000.6.7f1 Editor Mono measure the public alpha-mask and local-art-bounds APIs. Every input is fully opaque RGBA32. Each workload receives 64 warm calls, calibration to at least 20 ms and 21 raw rounds. The second pair reverses process order. Table medians are medians of the three process medians.
| API and rectangle | Before median | After median | Paired after/before range |
|---|---|---|---|
| Mask, 16×16 in 1024×1024 | 3048.33 µs | 4.08 µs | 0.0009–0.0020 |
| Mask, 256×256 in 1024×1024 | 4124.69 µs | 418.16 µs | 0.0975–0.1123 |
| Mask, full 32×32 texture | 10.28 µs | 9.56 µs | 0.4968–1.2739 |
| Bounds, 16×16 in 1024×1024 | 3148.91 µs | 3.60 µs | 0.0007–0.0011 |
| Bounds, 256×256 in 1024×1024 | 2693.38 µs | 176.66 µs | 0.0601–0.0714 |
| Bounds, full 32×32 texture | 4.41 µs | 4.19 µs | 0.8962–0.9728 |
Both subrectangle workloads improve in every pair. The small full-texture mask control varies, including one slower candidate process; it establishes no stable speed improvement. These observations cover texture retrieval and each public query, but exclude texture creation and sprite creation. They do not qualify Editor source-PNG decoding, other texture formats, packed sprites, IL2CPP or WebGL performance. They are not total allocation-byte measurements.
Four native storage regressions fail against the original implementation and pass against the candidate. They check returned array length, nonzero source offsets, base-mip selection, exact colours, pivot mapping and independence from the texture. Three other-format controls retain converted-pixel semantics. The focused native correctness cohort passes 186 cases without skips. Each accepted timing process passes its six cases, returns raw exit zero and reaches both output stream ends without a drain stop. Source hashes remain stable within each process. Loaded module identities and production assembly hashes distinguish the two variants.
The replay archive contains the two implementations, timing and correctness sources, all six complete NUnit trees, all 21-round output sets, process receipts, credential-checked logs, a hash inventory, analysis and the native controller. Its README records the base checkout and replay steps. The final XML-doc addition changes no executable statements in the measured reader. New replays receive their own source, assembly and process identities. A preliminary launch selected the normal Runtime assembly and ran zero cases; the runner rejected it and it contributes no accepted observation.
Readable RGB24 subregions now decode only selected base-mip RGB bytes into an owned
region-sized Color32 array, with opaque alpha. Full-texture reads retain their conversion path.
Three new serial fresh-process pairs on Windows x64 Unity 6000.6.7f1 Editor Mono include both RGB24 workloads and RGBA32 controls. Each cell has 64 warm calls, calibration to at least 20 ms and 21 raw samples; the second pair reverses process order. Medians below are medians of three process medians. These observations are separate from the earlier RGBA32 campaign.
| Format | API and rectangle | Before median | After median | Paired after/before range |
|---|---|---|---|---|
| RGB24 | Mask, 32×32 in 32×32 | 11.124 µs | 5.331 µs | 0.4793–0.9171 |
| RGB24 | Bounds, 32×32 in 32×32 | 5.479 µs | 4.777 µs | 0.3627–0.9506 |
| RGB24 | Mask, 16×16 in 1024×1024 | 3557.488 µs | 4.180 µs | 0.0011–0.0016 |
| RGB24 | Bounds, 16×16 in 1024×1024 | 3759.325 µs | 4.732 µs | 0.0012–0.0014 |
| RGB24 | Mask, 256×256 in 1024×1024 | 4124.350 µs | 1076.925 µs | 0.2565–0.2726 |
| RGB24 | Bounds, 256×256 in 1024×1024 | 3643.050 µs | 633.947 µs | 0.1554–0.1740 |
| RGBA32 | Mask, 32×32 in 32×32 | 8.449 µs | 8.356 µs | 0.8170–1.4262 |
| RGBA32 | Bounds, 32×32 in 32×32 | 4.207 µs | 4.658 µs | 0.9210–2.9445 |
| RGBA32 | Mask, 16×16 in 1024×1024 | 4.377 µs | 4.071 µs | 0.8709–1.3538 |
| RGBA32 | Bounds, 16×16 in 1024×1024 | 3.515 µs | 3.299 µs | 0.6621–0.9978 |
| RGBA32 | Mask, 256×256 in 1024×1024 | 440.103 µs | 455.480 µs | 0.7707–1.3204 |
| RGBA32 | Bounds, 256×256 in 1024×1024 | 200.565 µs | 212.867 µs | 0.7556–1.1629 |
All four RGB24 subregion cells improve in every pair. The full-texture and existing RGBA32 paths vary, including slower candidate observations, and establish no stable improvement. The work excludes texture/sprite creation. It does not qualify packed sprites, Editor source-PNG decoding, other formats, IL2CPP, WebGL or total allocated bytes.
Eight native storage cases cover RGB24/RGBA32 returned array length, offsets, corners, mip selection, exact colours, pivot mapping and source independence. Before the RGB24 path, its four storage cases fail while the four RGBA32 cases pass; all eight pass afterward. The broader sprite correctness cohort passes 190 cases. All six accepted timing processes pass all 12 cases, return raw exit zero and reach both stream ends without a drain stop. Source and production assembly hashes stay stable per arm; loaded runtime module IDs are distinct between arms.
The native replay archive retains the frozen source snapshot, both reader variants, all six complete NUnit trees with every raw sample, loaded identities, process receipts, controllers and analysis. An earlier campaign overlapped a host benchmark and is excluded from timing acceptance; its raw captures remain retained separately.
Readable ARGB32, BGRA32 and Alpha8 subregions also keep only their selected base-mip pixels.
Four offsets and sizes per format exercise corners, nonzero offsets and mipmapped inputs.
All twelve storage controls fail against the earlier full-texture path. The updated reader
matches Unity's GetPixels32() conversion and owns a region-sized copy; changing it cannot
change the source texture. Full-texture and other-format conversion paths keep their behavior.
ARGB32 and BGRA32 bytes follow Unity's documented
ARGB32
and BGRA32
channel order. Alpha8 reads preserve the CPU conversion's black RGB channels and stored alpha;
this is checked against GetPixels32(), independently of shader sampling conventions.
The first candidate used white RGB and failed all five Alpha8 conversion controls. Correcting
the conversion preserves those assertions. The final local Unity 6000.6.7f1 PlayMode cohort
passes 224 cases, with zero failures and 72 existing skips. It exits zero with both streams
complete and stable source hashes. This establishes scoped storage and conversion behavior,
not new timing or allocation-byte measurements for these formats.
The additional replay archive retains the new format correctness results, the initial Alpha8 mismatch and the original reader source.
The initial RGB565 and RGBA4444 subregion implementation decoded selected base-mip
words into an owned region-sized Color32 array. RGB565 expands five- and six-bit
channels with bit replication and opaque alpha; RGBA4444 expands each nibble to
eight bits. The synchronous view below now avoids that copy for query callers.
Four native cases compare every one of the 65,536 packed encodings against Unity's own
GetPixels32, for both formats with and without mipmaps. They also check returned storage,
pivot mapping, units, source independence and a one-pixel top-right selection with nonzero
vertical offset. The original reader fails the four region-storage assertions; the decoder
passes the native colour comparisons. These are correctness and storage-size observations,
with no new timing or total allocation-byte claim. Consumer adoption remains tracked in
#1113.
For readable unpacked RGBA32, RGB24, ARGB32, BGRA32, Alpha8, RGB565 and RGBA4444
textures, alpha-mask and art-bounds queries now read the selected base
mip directly from texture memory. They do not allocate an intermediate Color32
array, for either a complete texture or a sprite subregion. Alpha-only scans read
alpha directly without decoding unused color channels.
The view stays inside the synchronous query. Public alpha masks still own their Boolean arrays. Ink traversal keeps an owned color snapshot across pooled work: a user pool callback can change the texture before traversal reads it. A real purge-callback regression verifies the original colors determine the result. Editor source-PNG reads keep an owned pixel copy because their temporary decoded texture is released before the query continues. Other texture formats retain Unity's conversion fallback. Internal callers that need a snapshot can still request owned pixels; those copies remain independent of the texture.
Six fresh Unity 6000.6.7f1 Editor Mono processes in A B B A A B order qualify the view change. Each passes all 43 selected cases, with raw-zero exits and both streams drained. The geometric candidate/baseline ratio across three pairs and three 256 × 256 sprite patterns is 0.31699. The win is concentrated in dense bounds; narrow and transparent scans remain near baseline.
Median process medians, microseconds per bounds query:
| Sprite pattern | Owned pixels | Texture view |
|---|---|---|
| Fully opaque | 83.001 | 3.032 |
| One opaque column | 297.865 | 286.708 |
| Fully transparent | 293.468 | 287.875 |
All mask-overload and ink controls pass the preregistered regression guard. The single-pixel ink control is 6.9–8.7% slower in all three pairs; the other ink controls remain near baseline. That cost is retained in the record. These are headless Editor Mono measurements, with no player, ARM or total application claim.
Fourteen positive-control-backed allocation cases cover all seven formats at 6 × 6 and 30 × 30 selected rectangles. Each observes 16 events for 16 owned pixel reads and zero for the corresponding texture views. The native thread byte counter did not qualify, so this establishes event removal rather than a total allocation-byte bound.
The 2,142 raw observations include the pool helper, bounds and ink controls. The qualification record retains all ratios, selection criteria, source hashes, loaded method identities, DLL hashes and healthy process receipts.
📦 Unity Helpers | 📖 Documentation | 🐛 Issues | 📜 MIT License
- Inspector Button
- Inspector Conditional Display
- Inspector Grouping Attributes
- Inspector Inline Editor
- Inspector Overview
- Inspector Selection Attributes
- Inspector Settings
- Inspector Validation Attributes
- Utility Components
- Visual Components
- Data Structures
- Helper Utilities
- Math And Extensions
- Pooling Guide
- Random Generators
- Reference Identity
- Reflection Helpers
- Singletons
- Asset Change Detection
- Asset Validation
- Authored Asset Validation
- Build Profile Scenes
- Editor Tools Guide
- Failed Tests Exporter
- Scene Canonicalization
- Sprite Animation Motion
- Test Run Reporter
- Unity Method Analyzer
- Ai Model Backends
- Bundled Assembly Conflicts
- Devcontainer Persistence
- Mcp Ecosystem
- Mcp Local Setup
- Odin Migration Guide
- Unity Devcontainer Licensing
- Agent Iteration
- Analyzers
- Baseline Tests Performance
- Bendable Line Sampling
- Bit Lookup Tables
- Dictionary Key Performance
- Enum Helpers Performance
- Enumeration Audit
- Ilist Sorting Performance
- Json Codegen Performance
- Local Pools
- Ownership Audit
- Random Performance
- Reflection Performance
- Performance
- Singleton Policy Fixtures
- Tree 2d Performance
- Tree 3d Performance
- Sprite Bounds Row Scan
- Sprite Ink Traversal
- Sprite Region Read
- Synchronous Test Lifecycle