Skip to content

Make use of GetMany to improve perf of CopyTo - #2517

Open
Manodasan Wignarajah (manodasanW) wants to merge 9 commits into
staging/3.0from
manodasanw/getMany
Open

Make use of GetMany to improve perf of CopyTo#2517
Manodasan Wignarajah (manodasanW) wants to merge 9 commits into
staging/3.0from
manodasanw/getMany

Conversation

@manodasanW

@manodasanW Manodasan Wignarajah (manodasanW) commented Aug 11, 2026

Copy link
Copy Markdown
Member

Measured IList<T>.CopyTo over 100,000-element native IVector<T> instances using the CollectionsPerf.GetMany* benchmarks.

Scenario Before After Improvement
int 10.55 ns/item 0.111 ns/item ~95× faster
string 61.27 ns/item 37.99 ns/item ~38% faster
projected object 88.24 ns/item 80.49 ns/item ~9% faster

Measured a native component calling IVector<int>.GetMany on a managed int[] containing 100,000 elements.

Implementation Mean per item Relative
Baseline — IList<T> indexer loop 0.652 ns 1.00×
Optimized — direct span copy 0.116 ns 0.18×

The optimized path is approximately 5.6× faster, reducing per-item cost by ~82%, with no managed allocations reported.

Copy IList<string> values through a single IVector.GetMany ABI call with balanced HSTRING cleanup, falling back only when a provider returns fewer items.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ddbd67fd-01c2-4b1b-b23f-f9eb0ad8f70e
Batch ICollection<T>.CopyTo through IVector<T>.GetMany across blittable, string, object, reference, value, nullable, key-value pair, Type, and Exception element categories. Add focused native-vector tests and string benchmark coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Validate native counts, preserve E_NOTIMPL fallback compatibility, correct GetMany vtable signatures, and add chunk-boundary string coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
No known conforming IVector implementation returns E_NOTIMPL from GetMany, so preserve normal failure propagation rather than masking incomplete providers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove defensive count clamping because it cannot validate or repair a malformed native provider and conforming implementations must return at most the requested capacity.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Use span copies for managed arrays and List<T> exposed through IVector<T>, while retaining the indexer fallback for arbitrary IList<T> implementations. Add coverage for offsets, limited capacity, empty requests, and each implementation path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep the TestWinRT-dependent benchmark call commented until the corresponding native benchmark API is available.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant