Skip to content

Conversation

@NickGerleman
Copy link
Contributor

@NickGerleman NickGerleman commented Mar 7, 2020

Addresses #4245, During deforking work I left a build logic typo which caused SystraceSection to noop. When trying to re-enable in deforked React Native, we end up having a compile error since stock Facebook code will pass doubles as an arg to SysTraceSection, and we will internally only accept string.

This was fixed in microsof/react-native by commenting out the SystraceSection call that passed a double. A real solution is to allow our implementation of FbSystraceSection to accept non-string args and convert to strings, as Facebook's seemingly does.

  • Add a SFINAE based overload for non-string-like types to call std::to_string on them
  • Move functions to be private instead of public

Still need a plan to validate this. Any recommendations @mganandraj @stecrain ?

Microsoft Reviewers: Open in CodeFlow

Addresses microsoft#4245, During deforking work I left a build logic typo which caused SysTraceSection to noop. When trying to reenable in deforked React Native, we end up having a compile error since stock Facebook code will pass doubles as an arg to SysTraceSection, and we will internally only accept string.

This was fixed in microsof/react-native by commenting out the SysTraceSection call that passed a double. A real solution is to allow our implementation of FbSystraceSection to accept non-string args and convert to strings, as Facebook's seemingly does.

- Add a SFINAE based overload for non-string-like types to call std::to_string on them
- Move functions to be private instead of public

Still need a plan to validate this.
@NickGerleman NickGerleman requested a review from a team as a code owner March 7, 2020 14:35
@ghost ghost added the vnext label Mar 7, 2020
std::bool_constant<std::is_convertible<T, std::string>::value || std::is_constructible<std::string, T>::value>;

template <typename Arg, typename std::enable_if_t<ConsructsToString<Arg>::value> * = nullptr>
inline void push_arg(Arg &&arg) {
Copy link
Member

Choose a reason for hiding this comment

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

) [](start = 32, length = 1)

noexcept?
Generally noexcept functions are 10 times smaller in binary files.

Copy link
Contributor Author

@NickGerleman NickGerleman Mar 7, 2020

Choose a reason for hiding this comment

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

I actually disagree about this one.

We're calling throwing code (std::array and std::to_string throw, along with the tracing stuff Anandraj added), which means we the compiler might be generating implicit catch/terminates. These are often times larger than the EH map that would be generated. I know the compiler has some liberty to avoid the implicit catch if it can reason throwing never happens, but no idea how good it is at it, and any allocation means it is unavoidable.

This is worth it if we're going to be called by noexcept code because we can pay that price in the leaf nodes to allow callers to avoid the overhead, but these functions are exclusively called by Facebook throwing APIs, so we essentially pay the price for a catch for nothing.

We've seen this issue practically in Word. Before a lot of the fixup that happened of shared libraries, moving Word's Clang build from bulk throwing to bulk noexcept increased binary size due to these implicit catches.

The way I've been thinking to approach this is:

  1. If we're sandwiched between throwing code, don't use noexcept. This is both to avoid implicit catch overhead and for correctness/safety.
  2. Try to use noexcept everywhere if we have a large object graph that we control and can ensure nothing is mixed internal to the boundary.

This whole thing is also partially mitigated by recent-ish MSVC changes that drastically reduce EH map size on x64.

Copy link
Member

@vmoroz vmoroz left a comment

Choose a reason for hiding this comment

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

:shipit:

Constructable was sort of wrong before, because we're actually doing assignment, but even then we likely only want things that allow implicit conversions.
@chrisglein
Copy link
Member

Fixes #4245

FYI to @NickGerleman , if you use the language "Fixes" github knows to link the issue and the PR in a special way.

@NickGerleman
Copy link
Contributor Author

Fixes #4245

FYI to @NickGerleman , if you use the language "Fixes" github knows to link the issue and the PR in a special way.

Mind Blown

@NickGerleman
Copy link
Contributor Author

I'm still having some trouble recording events, even with a WPR profile, but confirmed with a debugger we send sane things to generated EventWrite functions. Going to check this in.

@NickGerleman NickGerleman merged commit 7fe8da1 into microsoft:master Mar 9, 2020
@NickGerleman NickGerleman deleted the fix-etw branch March 9, 2020 19:49
NickGerleman added a commit to NickGerleman/react-native-windows that referenced this pull request Mar 9, 2020
* Fix Support For SysTraceSection

Addresses microsoft#4245, During deforking work I left a build logic typo which caused SysTraceSection to noop. When trying to reenable in deforked React Native, we end up having a compile error since stock Facebook code will pass doubles as an arg to SysTraceSection, and we will internally only accept string.

This was fixed in microsof/react-native by commenting out the SysTraceSection call that passed a double. A real solution is to allow our implementation of FbSystraceSection to accept non-string args and convert to strings, as Facebook's seemingly does.

- Use type traits to call std::to_string on args not convertible to string
- Move functions to be private instead of public

Still need a plan to validate this.

* Simplify things a bit

* Solely rely on is_convertible

Constructable was sort of wrong before, because we're actually doing assignment, but even then we likely only want things that allow implicit conversions.
ghost pushed a commit that referenced this pull request Mar 9, 2020
* Fix Support For SysTraceSection

Addresses #4245, During deforking work I left a build logic typo which caused SysTraceSection to noop. When trying to reenable in deforked React Native, we end up having a compile error since stock Facebook code will pass doubles as an arg to SysTraceSection, and we will internally only accept string.

This was fixed in microsof/react-native by commenting out the SysTraceSection call that passed a double. A real solution is to allow our implementation of FbSystraceSection to accept non-string args and convert to strings, as Facebook's seemingly does.

- Use type traits to call std::to_string on args not convertible to string
- Move functions to be private instead of public

Still need a plan to validate this.

* Simplify things a bit

* Solely rely on is_convertible

Constructable was sort of wrong before, because we're actually doing assignment, but even then we likely only want things that allow implicit conversions.
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.

3 participants