feat(profiling): keep string cache data alive longer #2668
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
PROF-9796
At the high-level, there are two wins here:
Details
This uses the new allocators in libdatadog to build a
StringSet
, and drops the old string table from the code. Like the newStringTable
in libdatadog v9, the string data for theStringSet
is held in an arena. However, it doesn't track insert order, nor hand out ids. It returns references to interned data instead, like a regular set.We store
ThinStr<'a>
s in the runtime cache, asusize
s. This bit is unsafe because the lifetime of the cache doesn't fit nicely in the borrow checker's semantics. However, the implementation guarantees that the data lives long enough.The run time cache is empty on each request, but the table data is still around. So we'll re-establish links to the cache to the data, but we don't have to rebuild the set structure as much compared to the previous implementation
If the allocators powering the string set report memory over 2 MiB at the end of a request, then the string set will start over. This particular number was chosen because it is the same size used for the chunk size of the chain allocator powering the set. The idea is that if we have more than one chunk, then maybe we're too big. We also don't want to look like a memory leak, and sizes over 2 MiB may start to look like we're leaking memory as we slowly use more and more.
Reviewer checklist