Add support for `proxy_view` and complementary infrastructure by mingxwa · Pull Request #218 · microsoft/proxy · GitHub
Skip to content
This repository was archived by the owner on Jan 29, 2026. It is now read-only.

Add support for proxy_view and complementary infrastructure#218

Merged
mingxwa merged 6 commits into
microsoft:mainfrom
mingxwa:user/mingxwa/view
Dec 17, 2024
Merged

Add support for proxy_view and complementary infrastructure#218
mingxwa merged 6 commits into
microsoft:mainfrom
mingxwa:user/mingxwa/view

Conversation

@mingxwa

@mingxwa mingxwa commented Dec 14, 2024

Copy link
Copy Markdown

Changes

  • Added class template observer_facade<F> for observing a proxy<F> via a raw pointer.
  • Added alias template proxy_view<F> = proxy<observer_facade<F>>.
  • Added alias template add_view<F> in basic_facade_builder to allow implicit conversion from proxy<F> to proxy_view<F> or proxy_view<const F>.
  • Added unit tests accordingly.

@mingxwa mingxwa requested review from guominrui and tian-lt December 14, 2024 06:37
@mingxwa mingxwa marked this pull request as ready for review December 14, 2024 06:43

@Shuenhoy Shuenhoy left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the implementation!

In general, this is what I expected.

I think there can be some additional tests on the behaviors about const:

  • const view from const proxy
const pro::proxy<TestFacade> p1 = ...;
pro::proxy_view<const TestFacade> p2 = p1;
  • const view from non const view
pro::proxy_view<TestFacade> p1 = ...;
pro::proxy_view<const TestFacade> p2 = p1;
  • const view from const raw
const int a = 0;
pro::proxy_view<const TestFacade> p = &a;

A small question: what is the consideration that the view needs to be explicitly added for each facade? Reducing compilation time and binary size? Avoiding misuses?

@mingxwa

mingxwa commented Dec 15, 2024

Copy link
Copy Markdown
Author

@Shuenhoy

Copy link
Copy Markdown

Thanks for the clarification.

// If p3 = p2 is defined to be equivalent to the following line of code, it won't compile.
// Therefore, I prefer not to define the conversion from proxy_view proxy_view.
// p3 = &std::as_const(foo);

My understanding is that the root issue stems from that proxy<const Facade> is not a thing, which would be something that behaves like ignoring the non-const dispatches (therefore accepting a const raw pointer). But that will probably be out of scope of the "view" topic. So I think this pr can skip const view from non-const view conversion for now, and maybe implement it if you would want to add something like proxy<const Facade> in the future.

@tian-lt

tian-lt commented Dec 16, 2024

Copy link
Copy Markdown
Collaborator

Suggest adding benchmark cases to see the perf of proxy_view

@mingxwa

mingxwa commented Dec 16, 2024

Copy link
Copy Markdown
Author

@tian-lt I added benchmarks for proxy_view vs virtual functions. The result matches my expectations. Compared to proxy, proxy_view is a little bit slower when the underlying type is small (because it needs to dereference the pointer), and faster when the underlying type is big. Compared to virtual functions, proxy_view is still generally faster. See the generated report from the CI build.

@mingxwa

mingxwa commented Dec 16, 2024

Copy link
Copy Markdown
Author

Comment thread tests/proxy_view_tests.cpp
Comment thread tests/proxy_view_tests.cpp Outdated
@mingxwa mingxwa merged commit 016ec22 into microsoft:main Dec 17, 2024
@mingxwa mingxwa deleted the user/mingxwa/view branch December 17, 2024 06:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants