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 StringBuilder per thread and remove Lazy from GetRuntimeClassName. #1381

Merged

Conversation

jlaanstra
Copy link
Collaborator

Remove uses of Lazy in InspectableInfo and uses a StringBuilder cache per thread to reduce memory waste for GetRuntimeClassName.

@jlaanstra jlaanstra changed the title Cache StringBuilder per thread to speed up GetRuntimeClassName. Cache StringBuilder per thread and remove Lazy from GetRuntimeClassName. Nov 11, 2023
return _runtimeClassName;
}

public string RuntimeClassName => _runtimeClassName ?? MakeRuntimeClassName();
Copy link
Member

Choose a reason for hiding this comment

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

Nit: can simplify this by just moving the code for MakeRuntimeClassName in the getter (using a body), rather than needing the separate method there, which is only ever used here anyway?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the pattern followed elsewhere so sticking with that.

Copy link
Member

Choose a reason for hiding this comment

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

But it's... Not a great pattern? And it's also wasteful (more IL size and extra JIT work for no reason), not to mention unnecessarily verbose. We should try to improve the codebase as we find things, rather than just sticking to existing code patterns that are not good in the first place. Of course, this can be a follow up 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not saying that we shouldn't change it but I'd rather change it everywhere at the same time :).

@jlaanstra jlaanstra merged commit 3840267 into microsoft:staging/AOT Nov 16, 2023
1 check passed
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.

3 participants