Replies: 1 comment 1 reply
-
lol, ok disregard this - apparently you swapped everything from std::forward to static_cast while I was asleep 😂 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When I originally submitted this PR #11 , I had used static_cast instead of std::forward wherever possible.
Aside from consistency (which is absolutely important!) was there any reason for the change?
I bring this up in discussion rather than on the PR itself because I think it’s worth discussing the value of std::forward in general.
Due to its implementation, it creates an overload set, instantiates a function, and performs parameter based overload selection. This has a pretty significant cost for compile-time programs, especially when you’re calling the function on an arbitrarily large variadic pack.
Some research into the costs of std::forward was done by Louis Dionne a few years back, which subsequently led to the rewriting of boost::hana to replace all instances of std::forward with static_cast (boostorg/hana@540f665) - this single change resulted in a 14% compilation speed up!!
Another benefit that’s not mentioned, is when compiling without optimisations or without inlining, this also leads to a smaller binary size - as the explicit std::forward instantiations don’t need to be created and stored within the binary.
I made a small proof-of-concept godbolt to demonstrate that this reduction in binary size applies to tuplet too (at least throughout the tuple_cat demonstration) [insert link here when I’m at a computer]
Did you know about this scenario already? And if so, is there a reason for using std::forward over static_cast?
Beta Was this translation helpful? Give feedback.
All reactions