getsentry / getsentry/sentry-dotnet

Investigate improved performance of internal buffers

Open
#2,299 4 comments 0 reactions 0 assignees View on GitHub
.NET Feature Optimization
Dominant language
C#
Stars
770
Forks
248
Avg merge
3d 4h
Merged PRs (30d)
49

Description

### Problem Statement

We allocate a lot of `MemoryStream` buffers internally, in the hot path.

It may be beneficial to use [`Microsoft.IO.RecyclableMemoryStream`](https://github.com/microsoft/Microsoft.IO.RecyclableMemoryStream). This would reduce both allocations and garbage collection.

Thanks to @SeanFeldman for the suggestion.

### Solution Brainstorm

This would add a package dependency on [`Microsoft.IO.RecyclableMemoryStream`](https://www.nuget.org/packages/Microsoft.IO.RecyclableMemoryStream/) for all targets (it's not built-in). Thus, we should only consider this if performance gains are significant.

TODO:

- [ ] Locate a few key places to try this, such as buffering payloads in `EnvelopeItem`.
- [ ] Add some benchmarks to test current performance.
- [ ] Replace `MemoryStream` constructors and re-run benchmarks.
- [ ] If performance gains are significant, continue with usage throughout. Otherwise don't.

**Update:** We should look at `ArrayPool` as well. That would avoid the package dependency.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.