Hi,
What's our policy on using std::function in Blink? We have a number of
uses of it in blink code already but the Chromium guide explicitly
forbids it [1].
The reason I'm asking is because the recommended alternative,
base::Callback, is *significantly* slower. We're seeing a 5-10%
regression on some of the layout performance tests when using
base::Callback but a slight improvement when using std::function to
replace the same lambda [2] on both high- and low-end devices where
ArabicLineLayout gets ~12% slower with base::Callback [3] and ~1%
faster with std::function [4] .
If the ban applies, what's the recommended way to implement a
synchronous typed callback function? The base::Callback overhead is
somewhat problematic in this case.
Thanks
1: https://chromium-cpp.appspot.com/#library-blacklist
2: https://chromium-review.googlesource.com/c/chromium/src/+/1208728/4..5
3: https://pinpoint-dot-chromeperf.appspot.com/results2/1395c415640000
4: https://pinpoint-dot-chromeperf.appspot.com/results2/109cf38d640000
--
Emil
--
You received this message because you are subscribed to the Google Groups "platform-architecture-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to platform-architect...@chromium.org.
To post to this group, send email to platform-arc...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CADu_oUD%3DTqDB%3D0pjK9kwQaj3yhKyrTD7WWCFegO03LfgYWNZrg%40mail.gmail.com.
The guidelines for C++ usage in Blink are the same as the guidelines for C++ usage in Chrome, so std::function is banned in Blink =)1) It would be useful to understand where the performance difference between base::Callback and std::function are coming from: my guess is base::Callback involves more indirections, since the BindState is always heap-allocated. In contrast, std::function doesn't always require going to the heap.2) A discussion of whether or not to allow std::function probably belongs on c...@chromium.org (which I've added to this thread).DanielOn Tue, Sep 11, 2018 at 11:50 AM Emil A Eklund <e...@chromium.org> wrote:Hi,
What's our policy on using std::function in Blink? We have a number of
uses of it in blink code already but the Chromium guide explicitly
forbids it [1].
The reason I'm asking is because the recommended alternative,
base::Callback, is *significantly* slower. We're seeing a 5-10%
regression on some of the layout performance tests when using
base::Callback but a slight improvement when using std::function to
replace the same lambda [2] on both high- and low-end devices where
ArabicLineLayout gets ~12% slower with base::Callback [3] and ~1%
faster with std::function [4] .
If the ban applies, what's the recommended way to implement a
synchronous typed callback function? The base::Callback overhead is
somewhat problematic in this case.
On Tue, Sep 11, 2018 at 12:00 PM Daniel Cheng <dch...@chromium.org> wrote:The guidelines for C++ usage in Blink are the same as the guidelines for C++ usage in Chrome, so std::function is banned in Blink =)1) It would be useful to understand where the performance difference between base::Callback and std::function are coming from: my guess is base::Callback involves more indirections, since the BindState is always heap-allocated. In contrast, std::function doesn't always require going to the heap.2) A discussion of whether or not to allow std::function probably belongs on c...@chromium.org (which I've added to this thread).DanielOn Tue, Sep 11, 2018 at 11:50 AM Emil A Eklund <e...@chromium.org> wrote:Hi,
What's our policy on using std::function in Blink? We have a number of
uses of it in blink code already but the Chromium guide explicitly
forbids it [1].
The reason I'm asking is because the recommended alternative,
base::Callback, is *significantly* slower. We're seeing a 5-10%
regression on some of the layout performance tests when using
base::Callback but a slight improvement when using std::function to
replace the same lambda [2] on both high- and low-end devices where
ArabicLineLayout gets ~12% slower with base::Callback [3] and ~1%
faster with std::function [4] .
If the ban applies, what's the recommended way to implement a
synchronous typed callback function? The base::Callback overhead is
somewhat problematic in this case.Sorry I realize I didn't answer this question. I think the most common patterns (that don't involve std::function) are:- pass a function pointer- accept the functor as a template parameter so lambdas can be passed
--I'm guessing the latter doesn't work well for layout, but could the former be an option?Daniel
Thanks
1: https://chromium-cpp.appspot.com/#library-blacklist
2: https://chromium-review.googlesource.com/c/chromium/src/+/1208728/4..5
3: https://pinpoint-dot-chromeperf.appspot.com/results2/1395c415640000
4: https://pinpoint-dot-chromeperf.appspot.com/results2/109cf38d640000
--
Emil
--
You received this message because you are subscribed to the Google Groups "platform-architecture-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to platform-architect...@chromium.org.
To post to this group, send email to platform-arc...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CADu_oUD%3DTqDB%3D0pjK9kwQaj3yhKyrTD7WWCFegO03LfgYWNZrg%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "platform-architecture-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to platform-architect...@chromium.org.
To post to this group, send email to platform-arc...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CAF3XrKrMK2iq%3DxxnA%2BUQCPLZdREQTXjXdKeVGFZY%3DVhvX1hi6w%40mail.gmail.com.
Thanks for the background and suggestions everyone!
--
Emil
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CADu_oUCx6bp0yodEx4Un5dLxSRWfFZtOGJkZVsmPBcK1JDPSfQ%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CADu_oUBL4V5VE2Y-Y3YNPwLaazXzcJJ0HiK%2BmxoddZWQpZ4x-w%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "platform-architecture-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to platform-architect...@chromium.org.
To post to this group, send email to platform-arc...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CALcbsXANqs3UDdzj%3DJ-N8AaUTCx%2BBKxi2bX99X018t2%3DJPeUyA%40mail.gmail.com.
There seems to be about a dozen non-test uses of std::function in Chromium and similar amount in Blink, should those be fixed?
Alternatively, since there seems to be a performance difference between std::function and base::Callback, should we consider "unbanning" but discouraging std::function? As far as I know, one of the driving decisions for banning std::function was that base::Callback is a better replacement, but it seems that on the performance front that's not the case (this is a bit on a tangent from figuring out _why_ there is a performance difference)
On Tue, Sep 11, 2018 at 2:44 PM Vladimir Levin <vmp...@chromium.org> wrote:There seems to be about a dozen non-test uses of std::function in Chromium and similar amount in Blink, should those be fixed?Unless the policy changes, yes.Alternatively, since there seems to be a performance difference between std::function and base::Callback, should we consider "unbanning" but discouraging std::function? As far as I know, one of the driving decisions for banning std::function was that base::Callback is a better replacement, but it seems that on the performance front that's not the case (this is a bit on a tangent from figuring out _why_ there is a performance difference)^^^ That's actually why I'm asking the question about performance. If the performance divergence is executing an std::function is faster than executing a base::Callback<>, and we cannot make base::Callback<> match, then there might be a reason to explore unbanning std::function.However, if the divergence is in std::bind() vs base::Bind(), then that's less compelling as std::bind() is significantly different enough that I doubt we'd want to allow that.
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CALcbsXCzoZRhLQ-mx0ogMu870ieRKNYUynfYzTJawbQNLhGR0g%40mail.gmail.com.
On Tue, Sep 11, 2018, 14:50 Albert J. Wong (王重傑) <ajw...@chromium.org> wrote:On Tue, Sep 11, 2018 at 2:44 PM Vladimir Levin <vmp...@chromium.org> wrote:There seems to be about a dozen non-test uses of std::function in Chromium and similar amount in Blink, should those be fixed?Unless the policy changes, yes.Alternatively, since there seems to be a performance difference between std::function and base::Callback, should we consider "unbanning" but discouraging std::function? As far as I know, one of the driving decisions for banning std::function was that base::Callback is a better replacement, but it seems that on the performance front that's not the case (this is a bit on a tangent from figuring out _why_ there is a performance difference)^^^ That's actually why I'm asking the question about performance. If the performance divergence is executing an std::function is faster than executing a base::Callback<>, and we cannot make base::Callback<> match, then there might be a reason to explore unbanning std::function.However, if the divergence is in std::bind() vs base::Bind(), then that's less compelling as std::bind() is significantly different enough that I doubt we'd want to allow that.From my naive local tests, it seems that invoking a base::RepeatingCallback and invoking a std::function have similar performance. However, base::Bind is about a magnitude slower than creating std::function with std::bind or with a stateful lambda.
Is it possible to consider allowing std::function without allowing std::bind? The difference as I see it is that the only way (that I know of) to create a non-empty base::Callback is via base::Bind. Whereas std::function can be constructed out of a stateful lambda.
On Tue, Sep 11, 2018 at 4:22 PM Vladimir Levin <vmp...@chromium.org> wrote:On Tue, Sep 11, 2018, 14:50 Albert J. Wong (王重傑) <ajw...@chromium.org> wrote:On Tue, Sep 11, 2018 at 2:44 PM Vladimir Levin <vmp...@chromium.org> wrote:There seems to be about a dozen non-test uses of std::function in Chromium and similar amount in Blink, should those be fixed?Unless the policy changes, yes.Alternatively, since there seems to be a performance difference between std::function and base::Callback, should we consider "unbanning" but discouraging std::function? As far as I know, one of the driving decisions for banning std::function was that base::Callback is a better replacement, but it seems that on the performance front that's not the case (this is a bit on a tangent from figuring out _why_ there is a performance difference)^^^ That's actually why I'm asking the question about performance. If the performance divergence is executing an std::function is faster than executing a base::Callback<>, and we cannot make base::Callback<> match, then there might be a reason to explore unbanning std::function.However, if the divergence is in std::bind() vs base::Bind(), then that's less compelling as std::bind() is significantly different enough that I doubt we'd want to allow that.From my naive local tests, it seems that invoking a base::RepeatingCallback and invoking a std::function have similar performance. However, base::Bind is about a magnitude slower than creating std::function with std::bind or with a stateful lambda.That matches my expectations. IIRC, the big difference is std::bind() doesn't allocate.Is it possible to consider allowing std::function without allowing std::bind? The difference as I see it is that the only way (that I know of) to create a non-empty base::Callback is via base::Bind. Whereas std::function can be constructed out of a stateful lambda.It's been years since I looked at this, but my first thought is to create a BindStatic() that somehow produced base::Callback<> variant for simple cases (eg, no bound variables). The problem to solve doesn't seem to be allowing std::function as much as it is allow something that can hold a lambda or raw function w/o as much overhead.<not-well-thought-out-digression>I wonder for example if you could create hacked-up region-based memory management concept within which you could attach a lambda that puts itself into a crash-on-call state. Imagine an API as follows.{Region r; //base::RepeatingCallback<void(void)> cb = r.MakeCallback( /* some capturing lambda here */)synchronous_api(cb);}Region::MakeCallback() would return something that can be stored in a base::Callback<>, but at the end of the region would NULL out the bind_state_ or something like that.</not-well-thought-out-digression>
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CALcbsXDJCVQ1wpsUJYtz_hkyS%2ByXMMPiruXaZmEH53Am5FvAWA%40mail.gmail.com.
OOC, does base::Bind *need* to allocate the bind state on the heap? Would it cause problems for it to be a data member in the Callback class itself?
On Wed, Sep 12, 2018 at 11:53 AM Yuri Wiitala <m...@chromium.org> wrote:OOC, does base::Bind *need* to allocate the bind state on the heap? Would it cause problems for it to be a data member in the Callback class itself?That's essentially what my hack CL did. In general, I think it's impossible to do this and maintain a nice API. Callback/Bind has 2 major concepts:Callback - Generic, type-erased holder. It knows its runtime and nothing else. Corollary: the size is constantBind - The main engine for type inference. It analyzes the arguments given to create a correctly sized BindState. This is why it dynamically allocates.If we want to put the storage on the stack, then we need to be able to, statically, name a type with sufficient storage to holdthe bound parameters which doesn't seem easy.
class BindStateStorage {
public:
BindState* get();
private:
union {
char[kSmallBindStateSize] small_state_;
BindState* big_state_;
}
bool is_small_;
};
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CALcbsXAiJ8QWOHL4KE_5Z_v1Q0Xi82w-%2BH2UXV3jSqQt8ETZ%3DQ%40mail.gmail.com.
On Wed, Sep 12, 2018 at 1:08 PM, Albert J. Wong (王重傑) <ajw...@chromium.org> wrote:On Wed, Sep 12, 2018 at 11:53 AM Yuri Wiitala <m...@chromium.org> wrote:OOC, does base::Bind *need* to allocate the bind state on the heap? Would it cause problems for it to be a data member in the Callback class itself?That's essentially what my hack CL did. In general, I think it's impossible to do this and maintain a nice API. Callback/Bind has 2 major concepts:Callback - Generic, type-erased holder. It knows its runtime and nothing else. Corollary: the size is constantBind - The main engine for type inference. It analyzes the arguments given to create a correctly sized BindState. This is why it dynamically allocates.If we want to put the storage on the stack, then we need to be able to, statically, name a type with sufficient storage to holdthe bound parameters which doesn't seem easy.Crazy idea: what if BindStateStorage was like std::string which does small string optimization:class BindStateStorage {public:BindState* get();private:union {char[kSmallBindStateSize] small_state_;BindState* big_state_;}bool is_small_;};
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CALcbsXAOhvZ39Dn7CSno3_UNf%2BVqF%2Bjq%3DgvUS%2BRgq3zRSh87Sg%40mail.gmail.com.
Hi Albert,In your proposal, what happens when a callback outlives its region? Is it going to CHECK at runtime?
Also, if we're going to consider capturing lambdas, why not just allow them in a form of non-copyable/non-movable Callback variant? All std::function questions I saw (and asked myself) were about using std::function for local callbacks, which are invoked during a function call, and not copied/stored.How about this:void Foo(base::LocalCallback<int(int)>& callback) {callback.Run(42);...}int x = 3;base::LocalCallback<int(int)> cb = [&x](int a) { return a + x; };Foo(cb);
On Wed, Sep 12, 2018 at 3:55 PM Dmitry Skiba <dsk...@google.com> wrote:Hi Albert,In your proposal, what happens when a callback outlives its region? Is it going to CHECK at runtime?Yup. Exactly. That's what the unittest shows.Also, if we're going to consider capturing lambdas, why not just allow them in a form of non-copyable/non-movable Callback variant? All std::function questions I saw (and asked myself) were about using std::function for local callbacks, which are invoked during a function call, and not copied/stored.How about this:void Foo(base::LocalCallback<int(int)>& callback) {callback.Run(42);...}int x = 3;base::LocalCallback<int(int)> cb = [&x](int a) { return a + x; };Foo(cb);So this is what I tried first. I think we end up with the same problem which is that what is stores lambda callback inside LocalCallback<>? Specificallytemplate <typename Sig>class LocalCallback {template <typename Functor>LocalCallback(Functor my_lambda) {
/* What do you do here with my_lambda? How would you declare the field? */
}}
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CALcbsXD%2Bf-KsNpzBSfvzuhRLNDnfGj5JNwgAKnGd%2Bjw7qTpBuA%40mail.gmail.com.
On Wed, Sep 12, 2018 at 4:02 PM Albert J. Wong (王重傑) <ajw...@chromium.org> wrote:On Wed, Sep 12, 2018 at 3:55 PM Dmitry Skiba <dsk...@google.com> wrote:Hi Albert,In your proposal, what happens when a callback outlives its region? Is it going to CHECK at runtime?Yup. Exactly. That's what the unittest shows.Also, if we're going to consider capturing lambdas, why not just allow them in a form of non-copyable/non-movable Callback variant? All std::function questions I saw (and asked myself) were about using std::function for local callbacks, which are invoked during a function call, and not copied/stored.How about this:void Foo(base::LocalCallback<int(int)>& callback) {callback.Run(42);...}int x = 3;base::LocalCallback<int(int)> cb = [&x](int a) { return a + x; };Foo(cb);So this is what I tried first. I think we end up with the same problem which is that what is stores lambda callback inside LocalCallback<>? Specificallytemplate <typename Sig>class LocalCallback {template <typename Functor>LocalCallback(Functor my_lambda) {
/* What do you do here with my_lambda? How would you declare the field? */
}}Use std::function<Sig> ;) At least you get the safety is this is the only exception
The trade off is such a Functor wouldn't be passable into another API that was base::Callback<>based should that be interesting. One could hypothesize, especially in tests, wanting tocreate a local captured lambda that you could PostTask() around where you have externalsynchronization that ensures all tasks are completed before destruction...
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CALcbsXCVAZgQPavp-kfv3UupB38QAZ_w6FK%3DwEQyPfKy0g%3D3LQ%40mail.gmail.com.
The trade off is such a Functor wouldn't be passable into another API that was base::Callback<>based should that be interesting. One could hypothesize, especially in tests, wanting tocreate a local captured lambda that you could PostTask() around where you have externalsynchronization that ensures all tasks are completed before destruction...That seems like a reasonable limitation. One could always fallback to using base::Callback/base::Bind
On Tue, Sep 11, 2018 at 12:00 PM Daniel Cheng <dch...@chromium.org> wrote:
The guidelines for C++ usage in Blink are the same as the guidelines for C++ usage in Chrome, so std::function is banned in Blink =)
1) It would be useful to understand where the performance difference between base::Callback and std::function are coming from: my guess is base::Callback involves more indirections, since the BindState is always heap-allocated. In contrast, std::function doesn't always require going to the heap.2) A discussion of whether or not to allow std::function probably belongs on c...@chromium.org (which I've added to this thread).DanielOn Tue, Sep 11, 2018 at 11:50 AM Emil A Eklund <e...@chromium.org> wrote:Hi,
What's our policy on using std::function in Blink? We have a number of
uses of it in blink code already but the Chromium guide explicitly
forbids it [1].
The reason I'm asking is because the recommended alternative,
base::Callback, is *significantly* slower. We're seeing a 5-10%
regression on some of the layout performance tests when using
base::Callback but a slight improvement when using std::function to
replace the same lambda [2] on both high- and low-end devices where
ArabicLineLayout gets ~12% slower with base::Callback [3] and ~1%
faster with std::function [4] .
If the ban applies, what's the recommended way to implement a
synchronous typed callback function? The base::Callback overhead is
somewhat problematic in this case.
Sorry I realize I didn't answer this question. I think the most common patterns (that don't involve std::function) are:- pass a function pointer
- accept the functor as a template parameter so lambdas can be passed
I'm guessing the latter doesn't work well for layout, but could the former be an option?Daniel
Thanks
1: https://chromium-cpp.appspot.com/#library-blacklist
2: https://chromium-review.googlesource.com/c/chromium/src/+/1208728/4..5
3: https://pinpoint-dot-chromeperf.appspot.com/results2/1395c415640000
4: https://pinpoint-dot-chromeperf.appspot.com/results2/109cf38d640000
--
Emil
--
You received this message because you are subscribed to the Google Groups "platform-architecture-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to platform-architecture-dev+unsub...@chromium.org.
To post to this group, send email to platform-architecture-dev@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CADu_oUD%3DTqDB%3D0pjK9kwQaj3yhKyrTD7WWCFegO03LfgYWNZrg%40mail.gmail.com.
I'm guessing the latter doesn't work well for layout, but could the former be an option?Daniel
Thanks
1: https://chromium-cpp.appspot.com/#library-blacklist
2: https://chromium-review.googlesource.com/c/chromium/src/+/1208728/4..5
3: https://pinpoint-dot-chromeperf.appspot.com/results2/1395c415640000
4: https://pinpoint-dot-chromeperf.appspot.com/results2/109cf38d640000
--
Emil
--
You received this message because you are subscribed to the Google Groups "platform-architecture-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to platform-architect...@chromium.org.
To post to this group, send email to platform-arc...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/CADu_oUD%3DTqDB%3D0pjK9kwQaj3yhKyrTD7WWCFegO03LfgYWNZrg%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "platform-architecture-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to platform-architect...@chromium.org.
To post to this group, send email to platform-arc...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/platform-architecture-dev/795d165c-8403-40cd-9f01-663357b71bc6%40chromium.org.
std::function has a number of gotchas that make me hesitant to allow both (at least without better guidelines/recommendations of when std::function is appropriate).- std::function can only be copied, not moved. If the functor it captures has a significant amount of state, this copy is expensive.
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAF3XrKqBpWcchSNWiFPLvPBq6cAFndFxq09NdO0QP-qvbu7eog%40mail.gmail.com.
Lacking anything better, another alternative might be to have the function take an interface pointer and have the caller supply an implementation functor. This throws away some of the syntactic goodness, but has basically the interesting properties here.If this is a pattern we want to replicate elsewhere, we could consider providing something like LLVM's function ref, whose basic implementation is roughly this (the actual details are somewhat more subtle, but this is the gist):template <typename R, typename... A> class function_ref {public:template <typename Callable> function_ref(const Callable& c): func_(&Dispatch<Callable>), ptr_(&c) {}A operator()(A... args) const {return func_(std::forward<A>(args)...);}private:template <typename Callable>static R Dispatch(const void* p, A... args) {return (*static_cast<const Callable*>(ptr))(std::forward<A>(args)...);}using FunctionPointer = R(*)(void*, A...);FunctionPointer func_;const void* ptr_;};This is strictly dumber than std::function, but does the thing that seems to be desired here. It does give virtual dispatch to arbitrary lambdas and does not in any way extend their lifetime.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CACuR13f%2B6m0W8QgD7MAvhZ6t5%2BEL63CB1bdAxTEDH0rKK8Cjqg%40mail.gmail.com.
Karl Wiberg | Software Engineer | kwi...@google.com | +46 70 696 1024 |
Interesting!So, this particular variant of type-erasure I think only handles non-capturing callbacks. If this is all the we want, I think it'd be reasonable to folk it back into base::Callback<> as that's what base::Callback<> is doing as well (see equivalent code here https://cs.chromium.org/chromium/src/base/callback.h?q=Callback&sq=package:chromium&g=0&l=96)However, for emil's original example, there was a wish to bind as well, but not dynamically allocate.
On Mon, Sep 17, 2018 at 3:50 PM Albert J. Wong (王重傑) <ajw...@chromium.org> wrote:Interesting!So, this particular variant of type-erasure I think only handles non-capturing callbacks. If this is all the we want, I think it'd be reasonable to folk it back into base::Callback<> as that's what base::Callback<> is doing as well (see equivalent code here https://cs.chromium.org/chromium/src/base/callback.h?q=Callback&sq=package:chromium&g=0&l=96)However, for emil's original example, there was a wish to bind as well, but not dynamically allocate.As commented on the doc, LLVM's function_ref (and also WebRTC's FunctionView) work fine with capturing lambdas and do no extra allocation outside two-word struct.
On Mon, Sep 17, 2018 at 1:23 PM Jeremy Roman <jbr...@chromium.org> wrote:On Mon, Sep 17, 2018 at 3:50 PM Albert J. Wong (王重傑) <ajw...@chromium.org> wrote:Interesting!So, this particular variant of type-erasure I think only handles non-capturing callbacks. If this is all the we want, I think it'd be reasonable to folk it back into base::Callback<> as that's what base::Callback<> is doing as well (see equivalent code here https://cs.chromium.org/chromium/src/base/callback.h?q=Callback&sq=package:chromium&g=0&l=96)However, for emil's original example, there was a wish to bind as well, but not dynamically allocate.As commented on the doc, LLVM's function_ref (and also WebRTC's FunctionView) work fine with capturing lambdas and do no extra allocation outside two-word struct.Interesting... you are right. I misread that. But I'm trying to wrap my head around the memory safety guarantees of this.Is it that it is only ever used as an argument type and never declared on the stack?
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CALcbsXDEfvWwmeSBWTDeG5M0NA6hHGgquCy3%3DxfdfWR2gBq7PQ%40mail.gmail.com.