Skip to content

Conversation

@7H3LaughingMan
Copy link
Contributor

Converts TiledColor to a struct similar to how Color is defined in System.Drawing and other libraries. The actual value is a 32-bit unsigned integer with each octet representing a different component. Also defines several standard static colors that can be used.

These changes does manage to reduce the allocated memory and increases performance by a smidge.

@7H3LaughingMan 7H3LaughingMan force-pushed the color-struct branch 5 times, most recently from 421ab6d to adf0871 Compare May 1, 2025 21:52
@7H3LaughingMan
Copy link
Contributor Author

BenchmarkDotNet v0.13.12, Windows 11 (10.0.26100.3775)
Intel Core i5-14500, 1 CPU, 20 logical and 14 physical cores
.NET SDK 9.0.203
  [Host]     : .NET 8.0.15 (8.0.1525.16413), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.15 (8.0.1525.16413), X64 RyuJIT AVX2

Before Changes

Method Categories Mean Median Ratio Gen0 Gen1 Allocated Alloc Ratio
DotTiled MapFromInMemoryTmjString 4.953 μs 4.937 μs 1.00 0.4730 - 5.81 KB 1.00
TiledLib MapFromInMemoryTmjString 6.311 μs 6.197 μs 1.30 0.7401 0.0153 9.07 KB 1.56
DotTiled MapFromInMemoryTmxString 3.129 μs 3.116 μs 1.00 1.3580 0.0610 16.72 KB 1.00
TiledLib MapFromInMemoryTmxString 5.533 μs 5.549 μs 1.77 1.8921 0.1221 23.31 KB 1.39
TiledCSPlus MapFromInMemoryTmxString 6.857 μs 6.819 μs 2.19 2.6855 0.1221 33.23 KB 1.99

After Changes

Method Categories Mean Median Ratio Gen0 Gen1 Allocated Alloc Ratio
DotTiled MapFromInMemoryTmjString 4.428 μs 4.419 μs 1.00 0.4425 - 5.51 KB 1.00
TiledLib MapFromInMemoryTmjString 6.252 μs 6.224 μs 1.41 0.7401 0.0153 9.07 KB 1.65
DotTiled MapFromInMemoryTmxString 3.042 μs 3.036 μs 1.00 1.3390 0.0610 16.41 KB 1.00
TiledLib MapFromInMemoryTmxString 5.801 μs 5.710 μs 2.00 1.8921 0.1221 23.31 KB 1.42
TiledCSPlus MapFromInMemoryTmxString 6.755 μs 6.684 μs 2.23 2.6855 0.1831 33.16 KB 2.02

@7H3LaughingMan 7H3LaughingMan force-pushed the color-struct branch 2 times, most recently from f8beee4 to 64d41b6 Compare May 8, 2025 16:45
@7H3LaughingMan
Copy link
Contributor Author

I managed to squeeze out a little more performance by using StructLayout and FieldOffset, this way TiledColor is still the size of a uint but there is no need to constantly do bitwise operations to unpack the data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant