Skip to content

Avoid copying strings when serializing TraceEvent / lock only on buffer operations #52220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

hoxyq
Copy link
Contributor

@hoxyq hoxyq commented Jun 24, 2025

Summary:

Changelog: [Internal]

Mainly, 2 changes:

  1. PerformanceTracer::serializeTraceEvent(const TraceEvent& event) -> PerformanceTracer::serializeTraceEvent(TraceEvent&& event) for less copies, actually move strings from the TraceEvent into the serialized folly:object.
  2. When collecting events from the buffer, only lock when accessing buffer, not when serializing.

Differential Revision: D77164969

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner labels Jun 24, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77164969

hoxyq added a commit to hoxyq/react-native that referenced this pull request Jun 25, 2025
…er operations (facebook#52220)

Summary:

# Changelog: [Internal]

Mainly, 2 changes:
1. `PerformanceTracer::serializeTraceEvent(const TraceEvent& event)` -> `PerformanceTracer::serializeTraceEvent(TraceEvent&& event)` for less copies, actually move strings from the `TraceEvent` into the serialized `folly:object`.
2. When collecting events from the buffer, only lock when accessing buffer, not when serializing.

Reviewed By: rubennorte

Differential Revision: D77164969
@hoxyq hoxyq force-pushed the export-D77164969 branch 2 times, most recently from f6ecbf7 to 0efa21d Compare June 25, 2025 09:37
hoxyq added a commit to hoxyq/react-native that referenced this pull request Jun 25, 2025
…er operations (facebook#52220)

Summary:

# Changelog: [Internal]

Mainly, 2 changes:
1. `PerformanceTracer::serializeTraceEvent(const TraceEvent& event)` -> `PerformanceTracer::serializeTraceEvent(TraceEvent&& event)` for less copies, actually move strings from the `TraceEvent` into the serialized `folly:object`.
2. When collecting events from the buffer, only lock when accessing buffer, not when serializing.

Reviewed By: rubennorte

Differential Revision: D77164969
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77164969

2 similar comments
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77164969

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77164969

hoxyq added a commit to hoxyq/react-native that referenced this pull request Jun 25, 2025
…er operations (facebook#52220)

Summary:
Pull Request resolved: facebook#52220

# Changelog: [Internal]

Mainly, 2 changes:
1. `PerformanceTracer::serializeTraceEvent(const TraceEvent& event)` -> `PerformanceTracer::serializeTraceEvent(TraceEvent&& event)` for less copies, actually move strings from the `TraceEvent` into the serialized `folly:object`.
2. When collecting events from the buffer, only lock when accessing buffer, not when serializing.

Reviewed By: rubennorte

Differential Revision: D77164969
@hoxyq hoxyq force-pushed the export-D77164969 branch from 0efa21d to e044e4d Compare June 25, 2025 09:40
hoxyq added a commit to hoxyq/react-native that referenced this pull request Jun 25, 2025
…er operations (facebook#52220)

Summary:

# Changelog: [Internal]

Mainly, 2 changes:
1. `PerformanceTracer::serializeTraceEvent(const TraceEvent& event)` -> `PerformanceTracer::serializeTraceEvent(TraceEvent&& event)` for less copies, actually move strings from the `TraceEvent` into the serialized `folly:object`.
2. When collecting events from the buffer, only lock when accessing buffer, not when serializing.

Reviewed By: rubennorte

Differential Revision: D77164969
@hoxyq hoxyq force-pushed the export-D77164969 branch from e044e4d to 7ba59bb Compare June 25, 2025 09:56
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77164969

1 similar comment
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77164969

@hoxyq hoxyq force-pushed the export-D77164969 branch from 7ba59bb to 5aaa3c3 Compare June 25, 2025 10:01
hoxyq added a commit to hoxyq/react-native that referenced this pull request Jun 25, 2025
…er operations (facebook#52220)

Summary:
Pull Request resolved: facebook#52220

# Changelog: [Internal]

Mainly, 2 changes:
1. `PerformanceTracer::serializeTraceEvent(const TraceEvent& event)` -> `PerformanceTracer::serializeTraceEvent(TraceEvent&& event)` for less copies, actually move strings from the `TraceEvent` into the serialized `folly:object`.
2. When collecting events from the buffer, only lock when accessing buffer, not when serializing.

Reviewed By: rubennorte

Differential Revision: D77164969
hoxyq added 4 commits June 25, 2025 04:03
Summary:

# Changelog: [Internal]

- `bool tracing_` -> `std::atomic<bool> tracingAtomic_`.
- More doc-comments to explain the usage of mutex and atomics.
- `PerformanceTracer::isTracing()` -> `inline PerformanceTracer::isTracing()`.
- `uint64_t processId_` -> `const uint64_t processId_`.

The main change is that the boolean flag that controls "if we are tracing" is now atomic, which should eliminate potential data races. To avoid "logic" races, we are still going to lock mutex, and then check again. The use of `std::atomic` allows us to perform cheaper check first to avoid potentially unnecessary serializations from other systems that report events into `PerformanceTracer`.

Reviewed By: rubennorte

Differential Revision: D77053030
Summary:

# Changelog: [Internal]

`buffer_.push_back` -> `buffer_.emplace_back`

I didn't measure if there were any runtime wins from this, because I don't expect there would be. Let's avoid potential copies, if possible.

Reviewed By: rubennorte

Differential Revision: D77053032
…2196)

Summary:

# Changelog: [Internal]

Probably been overlooked for quite some time, but shouldn't be a bottleneck.

Reviewed By: motiz88

Differential Revision: D77148271
…er operations (facebook#52220)

Summary:

# Changelog: [Internal]

Mainly, 2 changes:
1. `PerformanceTracer::serializeTraceEvent(const TraceEvent& event)` -> `PerformanceTracer::serializeTraceEvent(TraceEvent&& event)` for less copies, actually move strings from the `TraceEvent` into the serialized `folly:object`.
2. When collecting events from the buffer, only lock when accessing buffer, not when serializing.

Reviewed By: rubennorte

Differential Revision: D77164969
@hoxyq hoxyq force-pushed the export-D77164969 branch from 5aaa3c3 to 925ec20 Compare June 25, 2025 11:04
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D77164969

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jun 25, 2025
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in ca647c1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants