Skip to content

Bug:map_view_base Lookup failure case is several orders slower due to C++ exceptions #1511

@ChrisGuzak

Description

@ChrisGuzak

Version

v2.0.250303.1

Summary

I created a synthetic benchmark to test the perf of the failed case of Lookup(), that generates a C++ exception (impl below hresult_out_of_bounds()), and it reports the following when compared to the OS implementation of ValueSet. Lookup is called in TryLookup to simplify usage.

CppWinRT Map
TryLookup fails
100000 iterations, 2021ms, 0ms per iteration

TryLookup succeeds
100000 iterations, 5ms, 0ms per iteration

ValueSet
TryLookup fails
100000 iterations, 2ms, 0ms per iteration

TryLookup succeeds
100000 iterations, 3ms, 0ms per iteration

2021ms vs 2ms

Antonio is working on fixing this in this PR.

...
    struct map_view_base : iterable_base<D, Windows::Foundation::Collections::IKeyValuePair<K, V>, Version>
    {
        V Lookup(K const& key) const
        {
...
            if (pair == static_cast<D const&>(*this).get_container().end())
            {
                throw hresult_out_of_bounds();
            }

Reproducible example

Expected behavior

No response

Actual behavior

No response

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions