Skip to content

[AI Refactoring] MediaVisionSource.IsSupportedColorSpace 매 호출 Enum.GetValues 리플렉션 + yield 재생성 → static FrozenSet 캐시 [Scope: src/Tizen.Multimedia.Vision] (2026-06-15) #7701

Description

@JoonghyunCho

[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.ContainsO(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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions