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: Perf. for fragments #1528

Merged
merged 35 commits into from
Jun 28, 2021
Merged

Feat: Perf. for fragments #1528

merged 35 commits into from
Jun 28, 2021

Conversation

marandaneto
Copy link
Contributor

@marandaneto marandaneto commented Jun 11, 2021

📜 Description

Feat: Perf. for fragments

💡 Motivation and Context

Able to start spans out of fragments

💚 How did you test it?

📝 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • No breaking changes

🔮 Next steps

@codecov-commenter
Copy link

codecov-commenter commented Jun 14, 2021

Codecov Report

Merging #1528 (d745940) into main (e7fb5c3) will not change coverage.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff            @@
##               main    #1528   +/-   ##
=========================================
  Coverage     76.03%   76.03%           
  Complexity     1955     1955           
=========================================
  Files           192      192           
  Lines          6765     6765           
  Branches        675      675           
=========================================
  Hits           5144     5144           
  Misses         1294     1294           
  Partials        327      327           
Impacted Files Coverage Δ
sentry/src/main/java/io/sentry/IHub.java 90.47% <66.66%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e7fb5c3...d745940. Read the comment docs.

@marandaneto marandaneto changed the base branch from main to gh-1523 June 16, 2021 12:19
Base automatically changed from gh-1523 to main June 23, 2021 12:48
@marandaneto marandaneto marked this pull request as ready for review June 24, 2021 14:23
enableAutoFragmentLifecycleTracing = enableAutoFragmentLifecycleTracing
)

private val isPerformanceEnabled = hub.options.isTracingEnabled && enableAutoFragmentLifecycleTracing
Copy link
Member

Choose a reason for hiding this comment

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

If we use the accessor like I suggested above, it would affect this too given the new hub could have perf enabled but the first not. So technically we'd need to evaluate this on each call hubAcessor().options....

Unless we get a new instance of this class for each Hub (each Sentry.init) in which case it would be fine we bind to the on Hub and disable when the hub closes.

Copy link
Member

Choose a reason for hiding this comment

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

Good catch @bruno-garcia. I think this would to the trick

Suggested change
private val isPerformanceEnabled = hub.options.isTracingEnabled && enableAutoFragmentLifecycleTracing
private val isPerformanceEnabled get() = hub.options.isTracingEnabled && enableAutoFragmentLifecycleTracing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its a new instance per activity, as the callback is bound to the fragment manager, and each activity has its own fragmentmanager, I guess its the same as #1528 (comment)
so in the case that a new activity is setup and isTracingEnabled is disabled, nothing is gonna happen.

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

On Cocoa, we only track spans until onResume is called because otherwise, the duration of a transaction would vary vastly. We could also create spans for onCreate, onStart and onResume. Then you get more insight into how long each of the lifecycle methods took.

enableAutoFragmentLifecycleTracing = enableAutoFragmentLifecycleTracing
)

private val isPerformanceEnabled = hub.options.isTracingEnabled && enableAutoFragmentLifecycleTracing
Copy link
Member

Choose a reason for hiding this comment

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

Good catch @bruno-garcia. I think this would to the trick

Suggested change
private val isPerformanceEnabled = hub.options.isTracingEnabled && enableAutoFragmentLifecycleTracing
private val isPerformanceEnabled get() = hub.options.isTracingEnabled && enableAutoFragmentLifecycleTracing

}

private fun stopTracing(fragment: Fragment) {
if (!isPerformanceEnabled || !isRunningSpan(fragment)) {
Copy link
Member

Choose a reason for hiding this comment

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

h: If isPerformanceEnabled is evaluated on each call it could be that it is disabled here and never finish the span. If isPerformanceEnabled is set to false and we have a running span we could just discard the span.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you cannot mutate the isPerformanceEnabled after the SDK is inited, so I don't see the point of taking care of this corner case, the same happens on ActivityLifecycleIntegration

Copy link
Member

Choose a reason for hiding this comment

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

Couldn't you do some crazy stuff like this?

public class MyApplication extends Application {

  private SentryOptions myOptions;

  @Override
  public void onCreate() {
    super.onCreate();
    
    SentryAndroid.init(
        this,
        options -> {
          myOptions = options;
        });

    // some time passes
    myOptions.setTracesSampleRate(null);
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you could, yes, this would be misusing the API hence not really a case that we should take care, if we take this option in consideration, there are N cases that would break the whole SDK, or using reflection and setting non null fields to null etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also init should be called only once, its part of the spec.

@marandaneto
Copy link
Contributor Author

On Cocoa, we only track spans until onResume is called because otherwise, the duration of a transaction would vary vastly. We could also create spans for onCreate, onStart and onResume. Then you get more insight into how long each of the lifecycle methods took.

the idea is that first, we measure the impact of adding spans for every single lifecycle method and later expand upon feedback, fragment has like 12 lifecycle methods, it's too noisy

@philipphofmann
Copy link
Member

philipphofmann commented Jun 25, 2021

the idea is that first, we measure the impact of adding spans for every single lifecycle method and later expand upon feedback, fragment has like 12 lifecycle methods, it's too noisy

Didn't know that. We currently don't have much "noise" on Android, so adding some makes sense to me as performance is about getting more insight. But I'm fine with the let's see how it goes approach.

@marandaneto
Copy link
Contributor Author

the idea is that first, we measure the impact of adding spans for every single lifecycle method and later expand upon feedback, fragment has like 12 lifecycle methods, it's too noisy

Didn't know that. We currently don't have much "noise" on Android, so adding some makes sense to me as performance is about getting more insight. But I'm fine with the let's see how it goes approach.

we've discussed this for Activity instrumentation, I'm just taking the same approach.
the difference is also that on Activitys and Fragments lifecycle, most of the work, if not only, is in the onCreate method, nothing else.

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

:shipit:

@marandaneto marandaneto merged commit a533114 into main Jun 28, 2021
@marandaneto marandaneto deleted the feat/perf-fragments branch June 28, 2021 08:51
@marandaneto marandaneto removed their assignment Nov 24, 2021
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.

5 participants