Skip to content
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

feat(performance): Add Time to Full Display and manual API for TTID #3654

Merged
merged 68 commits into from
Mar 18, 2024

Conversation

krystofwoldrich
Copy link
Member

@krystofwoldrich krystofwoldrich commented Mar 5, 2024

📢 Type of change

  • New feature

📜 Description

This PR adds manual API for measuring TTID and TTFD.

TTID and TTFD use React Native Native Components, android.view.View on Android and UIView on iOS. This enables the SDK to reliably hook into the rendering loop and wait for the next frame after the native component is created.

Why the need for native components?

We tested exposing the hook for the next frame to JS runtime, which turned out unreliable. When waiting for the component to mount and receiving the mount event back JS and based on that starting listening for the next frame, depending on the JS loop, the listen for the next frame might be significantly (10s, 100s ms) delayed. This only works in ideal scenarios, when JS runtime starts the listen immediately after receiving the mount event.

What does the API look like?

When combined with auto instrumentation only the components are needed. The Time To Display is only measured when record=true, any consequent re-renders are ignored until a new activeSpan.

The Time To Display spans can be started manually.

const initialDisplaySpan = startTimeToInitialDisplaySpan();
const fullDisplaySpan = startTimeToFullDisplaySpan();

function MyComponent() {
	return <View>
		<TimeToInitialDisplay record={true} />
		<TimeToFullDisplay record={false} />
	</View>
}

💚 How did you test it?

sample app, unit and integration tests

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled
  • All tests passing
  • No breaking changes

🔮 Next steps

  • Follow up PR with native implementation for new architecture
  • Add the documentation

Copy link
Contributor

github-actions bot commented Mar 8, 2024

iOS (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1237.61 ms 1239.88 ms 2.27 ms
Size 2.92 MiB 3.48 MiB 575.50 KiB

@krystofwoldrich krystofwoldrich marked this pull request as ready for review March 12, 2024 15:58
Copy link
Contributor

@brustolin brustolin left a comment

Choose a reason for hiding this comment

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

Cocoa code looks good.
There is one thing to fix in the TypeScript behaviour.

src/js/tracing/timetodisplay.tsx Outdated Show resolved Hide resolved
Copy link
Member

@markushi markushi left a comment

Choose a reason for hiding this comment

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

Looking good, left a few minor comments

@Override
public List<ViewManager> createViewManagers(
ReactApplicationContext reactContext) {
return List.of(
Copy link
Member

Choose a reason for hiding this comment

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

m: List.of is only available in Java 9 or newer, I think it would be safer to use Arrays.asList() from the java.util.Arrays package.

Base automatically changed from @krystofwoldrich/add-ttid to main March 18, 2024 11:32
Copy link
Contributor

@brustolin brustolin left a comment

Choose a reason for hiding this comment

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

LGTM!

@krystofwoldrich krystofwoldrich merged commit cc9666e into main Mar 18, 2024
53 of 56 checks passed
@krystofwoldrich krystofwoldrich deleted the @krystofwoldrich/add-ttid-manual-api branch March 18, 2024 12:56
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.

4 participants