Skip to content

Improve perf, especially around heap allocations #171

Description

@brantburnett

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions