[Type: Refactoring]
[Scope: src/Tizen.Multimedia.Vision]
[Priority: 🟡 Improvement]
[Lens: Performance, Modernization]
Observation
IsSupportedColorSpace delegates to the SupportedColorSpaces property, which is a yield-based iterator that calls Enum.GetValues(typeof(VisionColorSpace)) and converts every element on each enumeration.
MediaVisionSource.cs:166:
public static bool IsSupportedColorSpace(ColorSpace colorSpace)
{
return SupportedColorSpaces.Contains(colorSpace);
}
...
public static IEnumerable<ColorSpace> SupportedColorSpaces
{
get
{
foreach (VisionColorSpace value in Enum.GetValues(typeof(VisionColorSpace)))
{
yield return value.ToCommonColorSpace();
}
}
}
Problem
Performance + Modernization. Each IsSupportedColorSpace call (and each SupportedColorSpaces enumeration) performs: (a) Enum.GetValues(typeof(...)) — reflection + a boxed VisionColorSpace[] allocation, (b) the ToCommonColorSpace() switch per element, (c) a linear Enumerable.Contains scan with per-element boxing through IEnumerable<ColorSpace>. All of this recomputes a fixed, static ~11-element set on every call.
Proposed Improvement
Materialize the set once into a static readonly FrozenSet<ColorSpace> (.NET 8; the assembly targets net8.0) and back both members with it. SupportedColorSpaces keeps its IEnumerable<ColorSpace> signature by returning the frozen set.
Before/After:
private static readonly FrozenSet<ColorSpace> s_supportedColorSpaces =
Enum.GetValues<VisionColorSpace>().Select(v => v.ToCommonColorSpace()).ToFrozenSet();
public static bool IsSupportedColorSpace(ColorSpace colorSpace)
=> s_supportedColorSpaces.Contains(colorSpace);
public static IEnumerable<ColorSpace> SupportedColorSpaces => s_supportedColorSpaces;
(If an API Level 12 / platform-8.0 build band must also compile, substitute HashSet<ColorSpace> — it still removes the per-call reflection/allocation.)
Target Files
src/Tizen.Multimedia.Vision/MediaVision/MediaVisionSource.cs (L166-169, L244-253)
Expected Impact (Quantitative Metrics)
- Per
IsSupportedColorSpace call: 1 reflection call + 1 array allocation + 11-element conversion loop → 0 (computed once at type init)
- Lookup:
O(n) linear Enumerable.Contains → O(1) frozen-set probe
SupportedColorSpaces enumeration no longer re-runs reflection each time
API Compatibility Check
- Public API signature change: none (
IsSupportedColorSpace(ColorSpace) and IEnumerable<ColorSpace> SupportedColorSpaces preserved)
- Behavior change: none (same membership; enumeration order preserved by building from
Enum.GetValues)
- Tizen API Level floor:
FrozenSet requires the .NET 8 band (platform 10.0 / API 13+); the project targets net8.0 so this holds. Use HashSet<ColorSpace> if an older band must compile.
Impact Scope
SupportedColorSpaces referenced at 2 sites, both internal to the file; public getter signature preserved.
- Same-assembly only; no cross-assembly exposure
[Type: Refactoring]
[Scope: src/Tizen.Multimedia.Vision]
[Priority: 🟡 Improvement]
[Lens: Performance, Modernization]
Observation
IsSupportedColorSpacedelegates to theSupportedColorSpacesproperty, which is ayield-based iterator that callsEnum.GetValues(typeof(VisionColorSpace))and converts every element on each enumeration.MediaVisionSource.cs:166:Problem
Performance + Modernization. Each
IsSupportedColorSpacecall (and eachSupportedColorSpacesenumeration) performs: (a)Enum.GetValues(typeof(...))— reflection + a boxedVisionColorSpace[]allocation, (b) theToCommonColorSpace()switch per element, (c) a linearEnumerable.Containsscan with per-element boxing throughIEnumerable<ColorSpace>. All of this recomputes a fixed, static ~11-element set on every call.Proposed Improvement
Materialize the set once into a
static readonly FrozenSet<ColorSpace>(.NET 8; the assembly targetsnet8.0) and back both members with it.SupportedColorSpaceskeeps itsIEnumerable<ColorSpace>signature by returning the frozen set.Before/After:
(If an API Level 12 / platform-8.0 build band must also compile, substitute
HashSet<ColorSpace>— it still removes the per-call reflection/allocation.)Target Files
src/Tizen.Multimedia.Vision/MediaVision/MediaVisionSource.cs(L166-169, L244-253)Expected Impact (Quantitative Metrics)
IsSupportedColorSpacecall: 1 reflection call + 1 array allocation + 11-element conversion loop → 0 (computed once at type init)O(n)linearEnumerable.Contains→ O(1) frozen-set probeSupportedColorSpacesenumeration no longer re-runs reflection each timeAPI Compatibility Check
IsSupportedColorSpace(ColorSpace)andIEnumerable<ColorSpace> SupportedColorSpacespreserved)Enum.GetValues)FrozenSetrequires the .NET 8 band (platform 10.0 / API 13+); the project targetsnet8.0so this holds. UseHashSet<ColorSpace>if an older band must compile.Impact Scope
SupportedColorSpacesreferenced at 2 sites, both internal to the file; public getter signature preserved.