Skip to content

TextLayout.GenerateLayout generates a massive amount of garbage #425

Answered by nolife99
nolife99 asked this question in Q&A
Discussion options

You must be logged in to vote

I've discovered that the massive allocations come from boxing (using Enum.HasFlags). This theoretically should be an easy fix.

if (flags[i].HasFlag(isByte))
{
byte b = reader.ReadByte();
dx = (short)(flags[i].HasFlag(signOrSame) ? b : -b);
}
else
{
if (flags[i].HasFlag(signOrSame))

Changing these to a simple bitwise AND operation removes all nearly all allocations

Replies: 1 comment 11 replies

Comment options

You must be logged in to vote
11 replies
@JimBobSquarePants
Comment options

@nolife99
Comment options

@JimBobSquarePants
Comment options

@nolife99
Comment options

Answer selected by nolife99
@JimBobSquarePants
Comment options

@nolife99
Comment options

@nolife99
Comment options

@JimBobSquarePants
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants