-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
StringPool class (ArrayPool<T>-like to cache strings) #3380
StringPool class (ArrayPool<T>-like to cache strings) #3380
Conversation
Thanks Sergio0694 for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌 |
This PR has been marked as "needs attention 👋" and awaiting a response from the team. |
Hey @sonnemaf - just a small ping in case you missed the previous message from @michael-hawker here. Did you have a chance to test the final (current) implementation of |
I have tested it with my small test projects and found no issues. I think it is good to go. Signing it off. Can't wait to use it in my production code. |
Done. |
Oof was looking in the wrong place, yeah I see that now! Thank you! 😊 |
@michael-hawker Small ping in case you missed the notification, Fons approved this PR in his comment above (here), let me know if this is alright to merge now or if you'd like to have another look at it first. Excited to have this be part of the Preview 3 😄🚀 |
Hello @michael-hawker! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Awesome! 🎉🎉🎉 Thank you @sonnemaf for the review and feedbacks, and @michael-hawker for the approval and merge! 😄 |
PR Type
What kind of change does this PR introduce?
What is the new behavior?
This PR introduces a new
StringPool
type, inspired by theArrayPool<T>
type from the BCL, which can be used to cache and reusestring
instances. It is a similar concept to string interning, with the additional benefit of working with just aReadOnlySpan<char>
as input (so that thestring
allocation can be skipped entirely if an equal instance exists already), and offers more customizaton compared to string interning. It also allows users to reset the cache if needed, as well as creating multiple, configurable cache instances for different purposes, if necessary. This is the new API surface:Example usage
This sample shows how to parse a domain
string
from a given URL, usingStringPool
:Benchmarks
These are some benchmark results from here, when parsing a ~25 MB .csv file in UTF8 format with many duplicates. The difference between
StackallocGetOrAdd
andEmbeddedGetOrAdd
is whether the UTF16 conversion is done externally or using the implicitStringPool
API. In both cases, the memory usage goes down considerably, and performance is still pretty fast 🚀PR Checklist
Please check if your PR fulfills the following requirements:
Sample in sample app has been added / updated (for bug fixes / features)Icon has been created (if new sample) following the Thumbnail Style Guide and templates