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

Improve perf, especially around heap allocations #171

Open
brantburnett opened this issue Oct 7, 2022 · 0 comments
Open

Improve perf, especially around heap allocations #171

brantburnett opened this issue Oct 7, 2022 · 0 comments

Comments

@brantburnett
Copy link
Contributor

The current implementation uses a lot of byte[] instances internally, some of which are multiple kilobytes in size. There are some modern patterns that can help reduce the impact of this on garbage collection. Most of these, to one degree or another, can be used with .NET Standard 2.0 given a dependency on the System.Memory package.

  • Using buffers from the ArrayPool
  • Use of Memory<T> and Span<T> to represent slices of arrays rather than copying to new arrays
  • Reusing MemoryStream instances

I'm interested in improving some of these things myself. However, fully improving this will require some breaking changes to the API surface:

  • Accepting images as ReadOnlyMemory<byte> so the consumer may pass in an array slice
  • Some method of returning ReadOnlyMemory<byte> from generate to prevent an extra array copy from the MemoryStream
  • Rework SemanticTagBaseValue to avoid boxing value types to the heap, probably using type-specific variants

While were at it, there are possibly some other tweaks which could be done in the same breaking release. Perhaps using DateTimeOffset in DateField rather than DateTime, that sort of thing.

I'm curious if changes like this would be considered acceptable for a 4.x release. I don't want to put in the time if it isn't desired. I feel like this has a lot of value for high-traffic servers receiving lots of requests to generate passes, especially given potential calls to refresh pass data.

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

No branches or pull requests

1 participant