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 of Change
When trying to make Skottie work better, I noticed a few places where there was a less than ideal code path.
One performance improvement that can be applied to specific instances is to skip the object registration with the handler dictionary. Some objects are never returned from an API - such as
SKPaint
- because they are user objects and are always given to the native APIs and never stored.Other objects differ in that they are sometimes not stored in native code. In these cases we can skip the registration for specific methods - such as with the
SKUnregisteredDynamicMemoryWStream
used in the construction of theSKData
instance. This stream is only alive for the duration of theCreate
method, so we do not need to register the stream with the handle dictionary. These special objects can be created by implementing theISKSkipObjectRegistration
interface on a private class.Changes
SKData.AsStream()
now is a writeable stream and can be used to copy from another streamSKData Performance
This PR has a few changes that make creating SKData a faster and slimmer implementation.
My benchmark for the construction of SKData is below. There are 3 benchmarks:
Stream
objectsSource for benchmarks: https://github.com/mono/SkiaSharp/pull/2127/files#diff-85b6258ec115fee242f199220e54c7eb66db621306f800eebeee85fb054aa36c