Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache DocumentUrl in PortablePdbSymbolReader #79804

Merged
merged 1 commit into from
Dec 19, 2022

Conversation

MichalStrehovsky
Copy link
Member

This uses the exact same strategy as the unmanaged reader (Dictionary with a lock around this - wouldn't be my first choice, but we should use the same thing).

That was 100,000+ string allocations in a hello world:

image

Cc @dotnet/ilc-contrib

This uses the exact same strategy as the unmanaged reader (`Dictionary` with a `lock` around `this`).
@ghost
Copy link

ghost commented Dec 19, 2022

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

This uses the exact same strategy as the unmanaged reader (Dictionary with a lock around this - wouldn't be my first choice, but we should use the same thing).

That was 100,000+ string allocations in a hello world:

image

Cc @dotnet/ilc-contrib

Author: MichalStrehovsky
Assignees: MichalStrehovsky
Labels:

area-NativeAOT-coreclr

Milestone: -

@jkotas
Copy link
Member

jkotas commented Dec 19, 2022

That was 100,000+ string allocations in a hello world:

Why is not CachingMetadataStringDecoder taking care of caching these string allocations?

@MichalStrehovsky
Copy link
Member Author

That was 100,000+ string allocations in a hello world:

Why is not CachingMetadataStringDecoder taking care of caching these string allocations?

We call this API:

public string GetString(DocumentNameBlobHandle handle)
{
return BlobHeap.GetDocumentName(handle);
}

Which calls this:

public string GetDocumentName(DocumentNameBlobHandle handle)
{
var blobReader = GetBlobReader(handle);
// Spec: separator is an ASCII encoded character in range [0x01, 0x7F], or byte 0 to represent an empty separator.
int separator = blobReader.ReadByte();
if (separator > 0x7f)
{
throw new BadImageFormatException(SR.InvalidDocumentName);
}
var pooledBuilder = PooledStringBuilder.GetInstance();
var builder = pooledBuilder.Builder;
bool isFirstPart = true;
while (blobReader.RemainingBytes > 0)
{
if (separator != 0 && !isFirstPart)
{
builder.Append((char)separator);
}
var partReader = GetBlobReader(blobReader.ReadBlobHandle());
builder.Append(partReader.ReadUTF8(partReader.Length));
isFirstPart = false;
}
return pooledBuilder.ToStringAndFree();
}

The other GetString APIs pass the Utf8Decoder around:

public string GetString(StringHandle handle)
{
return StringHeap.GetString(handle, UTF8Decoder);
}

@MichalStrehovsky
Copy link
Member Author

Digging more into it, the problem seems to be that the caching string decoder caches things by pointer, but these document names are composed from chunks or something like that.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jkotas jkotas merged commit 6e69214 into dotnet:main Dec 19, 2022
@MichalStrehovsky MichalStrehovsky deleted the docurl branch December 19, 2022 18:17
@ghost ghost locked as resolved and limited conversation to collaborators Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants