Skip to content

[AI Task] Pre-size MediaVision result lists with known native count - #7786

Open
JoonghyunCho wants to merge 1 commit into
mainfrom
ai-task/issue-7700
Open

[AI Task] Pre-size MediaVision result lists with known native count#7786
JoonghyunCho wants to merge 1 commit into
mainfrom
ai-task/issue-7700

Conversation

@JoonghyunCho

Copy link
Copy Markdown
Member

Summary

The five Inference*Result constructors read the exact element count from native code, then built their List<T> with the default (zero) capacity and Add()-ed in a count-bounded loop. Since each result is constructed once per inferred frame (17+ points for pose landmarks, 68+ for facial landmarks), the ignored count caused ~3–5 avoidable backing-array reallocations plus element copies per frame. All five constructors — and the four legacy GetResults helpers with the same shape — now pass the already-known count as the initial List<T> capacity, so one right-sized array is allocated instead of a geometric growth chain. List contents and order are unchanged.

Changes

  • src/Tizen.Multimedia.Vision/MediaVision/InferencePoseLandmarkDetectorResult.cs: new List<Point>()new List<Point>((int)count)
  • src/Tizen.Multimedia.Vision/MediaVision/InferenceFacialLandmarkDetectorResult.cs: new List<Point>()new List<Point>((int)count)
  • src/Tizen.Multimedia.Vision/MediaVision/InferenceFaceDetectorResult.cs: new List<Rectangle>()new List<Rectangle>((int)count)
  • src/Tizen.Multimedia.Vision/MediaVision/InferenceObjectDetectorResult.cs: new List<Rectangle>()new List<Rectangle>((int)count)
  • src/Tizen.Multimedia.Vision/MediaVision/InferenceImageClassifierResult.cs: new List<string>()new List<string>((int)count)
  • src/Tizen.Multimedia.Vision/MediaVision/FaceDetector.cs: legacy GetResults list pre-sized with number
  • src/Tizen.Multimedia.Vision/MediaVision/ObjectDetector.cs: legacy GetResults list pre-sized with number
  • src/Tizen.Multimedia.Vision/MediaVision/ImageClassifier.cs: legacy GetResults list pre-sized with number
  • src/Tizen.Multimedia.Vision/MediaVision/FacialLandmarkDetector.cs: legacy GetResults list pre-sized with number

Mode

Refactoring

Verification

  • Build: passed (0 errors; remaining warnings are pre-existing in dependency projects)
  • Tests: N/A (no unit tests for this module; change is list initial capacity only, contents identical)
  • Benchmark: skipped (sdb error: no device attached)

Fixes #7700

…ixes #7700)

The five Inference*Result constructors and four legacy GetResults helpers
read the exact element count from native code but built their List<T>
with default capacity, causing repeated backing-array reallocations on
the per-frame hot path. Pass the known count/number as the initial
capacity so a single right-sized array is allocated. List contents and
order are unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@JoonghyunCho

Copy link
Copy Markdown
Member Author

⚠️ Benchmark skipped: No sdb device is attached (sdb devices returned an empty list), so the comparative benchmark could not be deployed or run. Manual benchmark verification is required. Expected effect per the issue analysis: backing-array reallocations per result drop from ~3 (17-point pose) / ~5 (68-point facial landmark) to 0, with one right-sized allocation replacing the geometric growth chain on the per-frame hot path.

@github-actions github-actions Bot added the API15 label Aug 2, 2026
@JoonghyunCho

Copy link
Copy Markdown
Member Author

🤖 [AI Review]

Reviewed — no findings.

Scope checked:

  • Verified all 9 changed allocation sites pass an already-known element count (number from the native detection callback in the 4 GetResults helpers, (int)count from GetResultCount in the 5 Inference*Result constructors) as the initial List<T> capacity, and that each loop adds exactly that many elements — capacity matches final size at every site.
  • Confirmed each GetResults helper keeps its number == 0 early-return before the allocation, so the empty path still avoids any allocation.
  • Checked the uint-to-int casts in the 5 constructors: counts are bounded native result counts, and in the detector helpers any throwing allocation would be routed to TrySetException by the existing try/catch in the callers.
  • All touched members are private static helpers or internal constructors — no public API surface or XML documentation impact.

No 🔴 critical issues, no 🟡 suggestions to flag.


Automated review — final merge decision rests with human reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant